源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-03-07 19:30 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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));

insert into customers(name) values("name1"),("name2");

select id from customers;
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MSSQLServer数据库会自动按递增的方式为主键赋
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部