mysql把主键定义为自动增长标识符类型
2014-07-16 00:00
681 查看
1、把主键定义为自动增长标识符类型
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key notnull, name varchar(15));
insert into customers(name) values("name1"),("name2");
一旦把id设为auto_increment类型,mysql数据库会自动按递增的方式为主键赋值。
在MS SQLServer中,如果把表的主键设为identity类型,数据库就会自动为主键赋值。例如:
create table customers(id int identity(1,1) primary key notnull, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MSSQLServer数据库会自动按递增的方式为主键赋
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key notnull, name varchar(15));
insert into customers(name) values("name1"),("name2");
一旦把id设为auto_increment类型,mysql数据库会自动按递增的方式为主键赋值。
在MS SQLServer中,如果把表的主键设为identity类型,数据库就会自动为主键赋值。例如:
create table customers(id int identity(1,1) primary key notnull, name varchar(15));
insert into customers(name) values("name1"),("name2");
select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MSSQLServer数据库会自动按递增的方式为主键赋
相关文章推荐
- mysql把主键定义为自动增长标识符类型
- mysql把主键定义为自动增长标识符类型
- 主键定义为自动增长类型
- mysql主主同步两个数据库同时写入,实现原理:自动增长主键不重复
- Mysql,SqlServer,Oracle主键自动增长的设置
- 给MySql表格添加一个自动增长的主键列
- 主键自动增长在Mysql,SqlServer,Oracle中的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql主键自动增长
- Mysql,SqlServer,Oracle,sqlite 主键自动增长的设置
- MySql 主键(自动增加)的数据类型所带来的错误
- Oracle, Mysql,SqlServer主键自动增长的设置
- mysql中主键自动增长时的几种情况
- ibatis获取主键自动增长ID(Oracle/MSSQL/mysql),取得刚插入的ID编号
- PowerDesigner设置MYSQL主键自动增长的方法
- 深入Mysql,SqlServer,Oracle主键自动增长的设置详解
- Hibernate产生自动增长类型主键策略
- Mysql,SqlServer,Oracle主键自动增长的设置