mysql创建表的字段时为什么不能用primary key和not null放在一起? 下面的命令错哪里了呢?create table user(serial int unsigned not null primary key,); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CREATE TABLE `tb_user` ( `id` int(10) NOT NULL auto_increment, .......} primary key本身应该是not null的吧? 下面这样就行,是不是primary key 默认是null啊?create table user1( serial int unsigned primary key auto_increment, birthday date);但是问题又来了create table user1( serial int unsigned primary key auto_increment, );这样就不行啊???到底primary key,auto_increment和not null这三个有什么关系啊?要怎么用呢? http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.htmlSERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE. create table user1(`serial` SERIAL); 但是问题又来了create table user1(serial int unsigned primary key auto_increment,);这样就不行啊???===================这个问题 是因为你多了个,语句出错create table user1(serial int unsigned primary key auto_increment);这样mysql还是能正确解析语句的。 CREATE TABLE `tb_account1` ( `fd_account_id` int(10) NOT NULL auto_increment PRIMARY KEY , `fd_account_no` varchar(50) NOT NULL default '', `fd_account_accountno` varchar(50) NOT NULL default '', `fd_account_name` varchar(50) NOT NULL default '', `fd_account_bank` varchar(50) NOT NULL default '', `fd_account_money` float(12,2) NOT NULL default '0.00', `fd_account_principal` varchar(20) NOT NULL default '', PRIMARY KEY (`fd_account_id`)) 正确用法 CREATE TABLE `tb_account1` ( `fd_account_id` int(10) NOT NULL auto_increment , `fd_account_no` varchar(50) NOT NULL default '', `fd_account_accountno` varchar(50) NOT NULL default '', `fd_account_name` varchar(50) NOT NULL default '', `fd_account_bank` varchar(50) NOT NULL default '', `fd_account_money` float(12,2) NOT NULL default '0.00', `fd_account_principal` varchar(20) NOT NULL default '', PRIMARY KEY (`fd_account_id`) ) 正确用法 不好意思,这个是错误的,我想用来检测有什么错误 结果返回 [Err] 1068 - Multiple primary key defined 嗯,好像auto_increment,primary key和not null都没有冲突,只是我在末尾多了个逗号是不是这样的呢??? 你执行下不就知道了。详细点的应该多看mysql文档。column_definition: col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'string'] [reference_definition] 关于echo的疑惑,请教高手 求大家帮忙解决这个问题啊。奇怪的php空白 关于php解析xml并存入数组的问题 能不能把PHP网页改下? 返回前页如何不刷新? 用phpmyadmin如何备份和恢复数据库 高分求解决方案!调查程序如何防止重复投票? 为什么会出现这个错误 Php怎么做无闪烁刷新的聊天室!用socket可以做吗?asp里面有好多讨论,不过没有在php里面看到过! php如何实现复选框选中的批量下载并按照标题名字来保存成文件名。 php怎么捕获异常? 怎么在PHP里面加一个按钮,一点击这个按钮就链接到下个页面,并要传递参数month=1给下个页面。
`id` int(10) NOT NULL auto_increment,
.......
}
下面这样就行,是不是primary key 默认是null啊?
create table user1(
serial int unsigned primary key auto_increment,
birthday date
);
但是问题又来了
create table user1(
serial int unsigned primary key auto_increment,
);
这样就不行啊???到底primary key,auto_increment和not null这三个有什么关系啊?要怎么用呢?
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE. create table user1(
`serial` SERIAL
);
create table user1(
serial int unsigned primary key auto_increment,
);
这样就不行啊???
===================
这个问题 是因为你多了个,
语句出错create table user1(
serial int unsigned primary key auto_increment
);
这样mysql还是能正确解析语句的。
`fd_account_id` int(10) NOT NULL auto_increment PRIMARY KEY ,
`fd_account_no` varchar(50) NOT NULL default '',
`fd_account_accountno` varchar(50) NOT NULL default '',
`fd_account_name` varchar(50) NOT NULL default '',
`fd_account_bank` varchar(50) NOT NULL default '',
`fd_account_money` float(12,2) NOT NULL default '0.00',
`fd_account_principal` varchar(20) NOT NULL default '',
PRIMARY KEY (`fd_account_id`)
)
正确用法
`fd_account_id` int(10) NOT NULL auto_increment ,
`fd_account_no` varchar(50) NOT NULL default '',
`fd_account_accountno` varchar(50) NOT NULL default '',
`fd_account_name` varchar(50) NOT NULL default '',
`fd_account_bank` varchar(50) NOT NULL default '',
`fd_account_money` float(12,2) NOT NULL default '0.00',
`fd_account_principal` varchar(20) NOT NULL default '',
PRIMARY KEY (`fd_account_id`)
)
正确用法
是不是这样的呢???
col_name type [NOT NULL | NULL] [DEFAULT default_value]
[AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
[COMMENT 'string'] [reference_definition]