您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql把主键定义为自动增长标识符类型

2024/4/15 11:36:25发布14次查看
分享下mysql中如何把主键定义为自动增长标识符类型。
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));-- www.jbxue.cominsert into customers(name) values(name1),(name2);select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,mssqlserver数据库会自动按递增的方式为主键赋值。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product