Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table and Field Name with Spaces 1

Status
Not open for further replies.

romh

Programmer
Jan 3, 2003
297
US
hi. I just converted an Acces 2000 database to mysql by exporting all of the tables from Access to mysql via ODBC and myODBC connection. Everything went well.
Now I am having trouble using select queries in mysql with table and field names that have spaces. I have read that field and table names with spaces should never be used. Do I have to remove all the table and field spaces? I have like 50 tables with spaces and columns in them. Can I surround these name with brackets [] or something else like in Access VBA.
Thanks alot.


 
You can use single quotes.

[tt]
SELECT 'column name'
FROM 'table name'
[/tt]

Just to state the obvious - table names and column names with spaces is not a good idea!

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
That didn;t work. The results just had the name of the column and not the actual data. Any more ideas? Thanks alot.

 
Yeah...sorry I wasted your time!

This will work:

[tt]
SELECT `column name`
FROM `table name`
[/tt]

Notice, this is not a single quote, but rather, a back-tick mark (usually under the escape button).

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
That worked like a charm. One more question:
Putting this back tick mark seems very annoying. Do all database engines support table or field names with spaces? For example, lets say that a year from now, I wanted to migrate from Mysql to Postgresql or MS SQL server, do they all support this spaces?

Do you think its best if I eliminate all spaces from my tables in Access and then export them again?

Thanks alot

 
I definitely think it's a good idea if this database will be around for a while. You could write a script of some sort using MySQL and PHP that will loop through all tables and columns and replace spaces with underscores. There would most likely be some research involved, but if you're interested, I'd be willing to help, along with, I'm sure, many other people on this forum.

Let us know.



*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Alright. Thanks alot. I appreciate your help. Let me go through the database and see how many fields and columns I have with spaces exactly and also decide if its best to replace it with an underscore or simply eliminate the space all together. I am definately keeping the database for a very long time, so I want to make the best decision.
Thanks again

 
Thanks alot. I'll download it tomorrow. Its 4:14am down here.
I'll reply tomorrow and give you my comments
Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top