468,740 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

reserved words as column names

My understanding is that using reserved words as column names is
allowable as long as they are quoted. I am trying to create a table
dynamically with columns defined by the first row of a text file I
import. Unfortunately, I have no control over the column names and
the data provider has chosen to use the word "USE" as a column name.
"USE" is a reserved word.

To handle this, I tried quoting the word during the CREATE TABLE
statement, as follows:

CREATE TABLE my_table (
'use' varchar(100)
)

But this is still causing an error. Any suggestions for avoiding the
obvious workaround of checking column names against reserved words and
changing them when there is a conflict? I'd like to use the column
names as defined by the data provider, if possible.

If it matters, I am running mySQL on Win32 and interfacing through
ColdFusion -- yes, rare and strange combination, but that's what the
client ordered :-)

Thanks all!

Matt
Jul 20 '05 #1
2 11722
Matthew Cascio wrote:
My understanding is that using reserved words as column names is
allowable as long as they are quoted. I am trying to create a table
dynamically with columns defined by the first row of a text file I
import. Unfortunately, I have no control over the column names and
the data provider has chosen to use the word "USE" as a column name.
"USE" is a reserved word.

To handle this, I tried quoting the word during the CREATE TABLE
statement, as follows:

CREATE TABLE my_table (
'use' varchar(100)
)

But this is still causing an error. Any suggestions for avoiding the
obvious workaround of checking column names against reserved words and
changing them when there is a conflict? I'd like to use the column
names as defined by the data provider, if possible.

If it matters, I am running mySQL on Win32 and interfacing through
ColdFusion -- yes, rare and strange combination, but that's what the
client ordered :-)


Use backticks `

CREATE TABLE my_table (
`use` varchar(100)
)

Remember to always use them in your queries as well eg SELECT `use` FROM
my_table

You really shouldn't use reserved words for column names if you can help it
though, but in this case I guess you need to.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #2
Matthew Cascio wrote:
My understanding is that using reserved words as column names is
allowable as long as they are quoted.


MySQL uses backticks (`), not quotes (') for this purpose.

This is nonstandard SQL; IIRC the SQL standard uses double-quotes (")
for delimited identifiers.

Regards,
Bill K.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bart Van der Donck | last post: by
1 post views Thread by Larry Bird | last post: by
1 post views Thread by JFB | last post: by
1 post views Thread by christianlott1 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.