Can I name a column name
in my mysql tables?
views:
172answers:
5You 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.
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
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
--------
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 |
+------+
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.