MySQL reports an error when creating a table. I can't understand it when I check the manual. Can you please solve it?
仅有的幸福
仅有的幸福 2017-06-06 09:52:09
0
2
709

Mysql reports an error when creating a table. I can’t understand it after checking the manual. Can you please give me a solution?

create table abc(
   id int unsigned  primary_key auto_increment,
   usename char(20) not null default '',
   gender char(1) not null default '',
   weight tinyint unsigned not null default 0, 
   birth date not null default 0,
   salary decimal(8,2) not null default '000000.00',
   lastlogin timestamp not null default 0,
   intro varchar(1500) not null default '',
)engine myisam charset=utf8;

Error report: 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 'primary_key auto_increment,username char(20) not null default '',gender c' at line 3

仅有的幸福
仅有的幸福

reply all(2)
伊谢尔伦

Creating an indexed database table requires adding back-quotes to the table name and attributes, and the position of your current primary key needs to be adjusted:

create table `abc`(
   `id` int unsigned auto_increment,
   `usename` char(20) not null default '',
   `gender` char(1) not null default '',
   `weight` tinyint unsigned not null default 0, 
   `birth` date not null default 0,
   `salary` decimal(8,2) not null default '000000.00',
   `lastlogin` timestamp not null default 0,
   `intro` varchar(1500) not null default '',
   primary key (`id`)
)engine myisam charset=utf8;

I just tried it. Except for primary key, other attributes and table names can be used without back-quotes. Even this is also possible:

create table abc(
   id int unsigned auto_increment,
   usename char(20) not null default '',
   gender char(1) not null default '',
   weight tinyint unsigned not null default 0, 
   birth date not null default 0,
   salary decimal(8,2) not null default '000000.00',
   lastlogin timestamp not null default 0,
   intro varchar(1500) not null default '',
   primary key (`id`)
)engine myisam charset=utf8;

Reference: mysql create and delete tables

Peter_Zhu

The declaration of primary_key is wrong, please solve it upstairs

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template