tags:

views:

172

answers:

5

Can I name a column name in my mysql tables?

+2  A: 

You should be fine calling a column 'name'. Check out http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html for more details on how to deal with reserved words.

Wrapping column names in the (`) character ensures that even reserved words won't be misinterpreted.

PHPexperts.ca
+1  A: 

Yes even though if its a person name I would recommend FirstName or FullName to be the column name to be more specific MYSQL Reservered Words

TStamper
A: 
CREATE TABLE mytest (name INT);

SELECT  *
FROM    mytest;

name
--------

In dubious cases you may enclose names into grave accents:

CREATE TABLE `CREATE TABLE` (name INT);

SELECT  *
FROM    `CREATE TABLE`;

name
--------
Quassnoi
+9  A: 

Why not just try it?

mysql> select name from name;
+------+
| name |
+------+
|    1 |
+------+

Also you can quote any names with ``.

mysql> select `from` from `from`;
+------+
| from |
+------+
|    1 |
+------+
Gleb
Nothing like simply trying it out!
artlung
Also reading the documentation
Cesar
+2  A: 

Regardless of whether or not you can, you might want to consider why you want to do it in the first place. Name of what? What kind of name? After a few years, if you look at the database schema, will you still remember these details?

I suggest it would be in your best interest to treat the column name the same as you would treat any variable names, and give it a descriptive name. Years down the road, you (or anyone who maintains your code) will be thanking you.

Keith B
Well, a column called 'name' in the 'companies' table would be fairly self explanatory...
ceejayoz