Web Hosting Talk







View Full Version : mysql cannot create column named default


adminsami
01-11-2007, 03:58 AM
Hello All,

I was trying to make a mysql database table with the following query. But it shows the error as given below. Table is created when I change the column name from default to default1. It seems the we cannot use the keyword 'default' as a column name. I need to use default itself as the column name. Any help appreciated.

mysql> CREATE TABLE testtable (
-> id smallint(5) unsigned NOT NULL auto_increment,
-> pos tinyint(3) unsigned default '0',
-> name char(255) default NULL,
-> type tinyint(1) unsigned default '1',
-> options char(255) default NULL,
-> default char(255) default NULL,
-> validation tinyint(1) unsigned default '0',
-> enable tinyint(1) unsigned default '1',
-> PRIMARY KEY (id)
-> ) TYPE=MyISAM;
ERROR 1064: You have an error in your SQL syntax near 'default char(255) default NULL,
validation tinyint(1) unsigned default '0',
' at line 7

dollar
01-11-2007, 05:34 AM
Thread moved, and why do you have to use the name default?

maxymizer
01-11-2007, 06:23 AM
Add quotes round the column name -> `default`

SamBox
01-11-2007, 06:37 AM
I've run into this problem before in trying to create table names that overlap with MySQL keywords (e.g., table creation attempt with column name "desc" creates problems). My advice ... try to avoid a column name of "default" (or, at the very least, make it less ambiguous --- e.g., "is_default", etc.)

zoid
01-11-2007, 07:07 AM
As others already mentioned this occurs because a MySQL keyword is used as field name. The best way would be to use a slightly modified name like SamBox mentioned for example. Otherwise you could use backticks to quote the name.
`default` char(255) default NULL,

creativeartist
01-11-2007, 12:10 PM
When you are using ALTER table command try to use the new field name and old field name in singl e quotes.I think this may be help for this

zoid
01-11-2007, 12:18 PM
try to use the new field name and old field name in singl e quotes.
Correct, however not quotes (') but backticks (`).

adminsami
01-18-2007, 01:12 AM
Thanks for all your inputs.

Dollar, its not written by me, but already written by one thirdparty software.

Xenatino
01-18-2007, 08:31 PM
As stated previously, the error is because default is one of MySQL's reserved words.

See here for more information on reserved words: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html