473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Correct syntax for table variable names containing a space

Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"

Regards
Dynamo

Jul 17 '05 #1
5 2386
On 22 Nov 2004 07:50:30 -0800, Dynamo <Dy***********@newsguy.com>
wrote:
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"


I'd suggest simply correcting the problem by NOT putting spaces in
such things as field names.

--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #2

(1) Don't do that.
(2) If you must, use backticks (`) around the offending column name:

$query = "INSERT INTO Catalogue (`Book title`) VALUES ('The Crow')";
---
Steve

Jul 17 '05 #3
.oO(Dynamo)
What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.


http://dev.mysql.com/doc/mysql/en/Legal_names.html

Micha
Jul 17 '05 #4
On 22 Nov 2004 07:50:30 -0800, Dynamo <Dy***********@newsguy.com> wrote:
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"


RENAME would be a good idea... spaces in a table name is a particularly bad
idea.

If you insist on keeping it, then double quotes are the standard method, to
produce a "quoted identifier".

$query = "INSERT INTO Catalogue (\"Book title\") VALUES ('The Crow')"

Specific databases may have alternatives, or not accept the standard
identifier quoting method, however you didn't state what database you're using.

(But anyway... rename the table... really).

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
Try putting the name in square brackets.
"Dynamo" <Dy***********@newsguy.com> wrote in message
news:cn*********@drn.newsguy.com...
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"

Regards
Dynamo

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Margaret MacDonald | last post by:
It appears that the 'table.field' dot notation is not preserved by php's mysql library. I can create some join 'SELECT a.id, b.id FROM table1 AS a, table2 AS b' but when I try to refer to the...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: David | last post by:
Hi, I have taken some SQL taken from a query in Access 2000, but I cannot seem to get it working correctly in my .asp page. strQuery = strquery & "FROM Schedule_Selector INNER JOIN ((Orders...
4
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
28
by: Sriram Rajagopalan | last post by:
Hi, I was interested to know if there is a way to use a variable name split across multiple lines in C. For example : int this_is_a_very_long_variable_name = 10; I would like to split...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.