开发者

phpMyadmin - Error #1064

When trying to create this table in my db, I get an error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned NOT NULL default '0', PRIMARY KEY (reminder_id), KEY reminder_id (rem' at line 5

CREATE TABLE reminder开发者_Python百科_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL default '',
reminder_desc text,
reminder_date varchar(8) unsigned NOT NULL default '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) TYPE=MyISAM;

Can anyone see what I'm doing wrong?


The problem is that you're trying to define a text field (varchar) as being unsigned, which is something that can only apply to a numerical field.

i.e.: "reminder_date varchar(8) unsigned NOT NULL default '0'," makes no sense.

However, as the field is called "reminder_date", I'm guessing you're attempting to store a date, in which case you really want to use MySQLs DATE field type.

e.g.: "reminder_date DATE NOT NULL,"

Additionally, if you're going to want to search on any of these fields, you should also add some indexes to speed up the searches. So, if you wanted to be able to search on the name and date, you could use:

CREATE TABLE reminder_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL DEFAULT '',
reminder_desc text,
reminder_date DATE NOT NULL,
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id),
KEY reminder_name (reminder_name),
KEY reminder_date (reminder_date)
) TYPE=MyISAM;


Just remove unsigned.

CREATE TABLE reminder_events (
reminder_id bigint(20) unsigned NOT NULL auto_increment,
reminder_name varchar(255) NOT NULL default '',
reminder_desc text,
reminder_date varchar(8) NOT NULL default '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) TYPE=MyISAM;


Write ENGINE instead of TYPE

CREATE TABLE reminder_events (
reminder_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
reminder_name VARCHAR(255) NOT NULL DEFAULT '',
reminder_desc TEXT,
reminder_date VARCHAR(8) NOT NULL DEFAULT '0',
PRIMARY KEY (reminder_id),
KEY reminder_id (reminder_id)
) ENGINE=MYISAM;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜