mysql建表報錯,查手冊看不懂,求解?
仅有的幸福
仅有的幸福 2017-06-06 09:52:09
0
2
669

mysql建表報錯,查手冊看不懂,求解?

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;

錯誤回報: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 ault not' line 3

仅有的幸福
仅有的幸福

全部回覆(2)
伊谢尔伦

建立帶有索引的資料庫表需要為表名和屬性添加反單引號,並且你目前的primary key的位置需要調整一下:

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;

我剛剛試了一下,除了primary key其他的屬性和表名不加反單引號也可以,即這樣也是可以的:

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;

參考:mysql建立和刪除表

Peter_Zhu

primary_key聲明的不對,樓上解

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!