开发者

MySQL reserved column names

I just ran into an error in my personal CMS software where it would tell me that the database build process was complete, but the table i was creating would consist only of an 'id' field. After some trial and error, I tried getting the exact query it was using and executing it, and found that the problem was the mysql error "#1060 - Duplicate column name 'name'". I switched the column name I was attempt开发者_JAVA百科ing to something else, and it worked flawlessly. I'm positive it's not a reserved column name, because its used as such on another table in the exact same database. Has anyone else ever run into this sort of problem?


This is how you get an #1060 error with your error message.

mysql> CREATE TABLE MyTbl (id INT, name VARCHAR(80), age INT, name VARCHAR(80)); 
ERROR 1060 (42S21): Duplicate column name 'name'

As you can see, the column name name has been used twice.

(Sure, it's not a reserved word, and sure, it could have worked in another table, where it only occurred once :-)


For the reserved names you can write with `, like this :

CREATE TABLE MyTbl (id INT, `name` VARCHAR(80), age INT);

And remove your 2nd column called name !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜