mysql把主键定义为自动增长标识符类型
发布时间:2020-12-12 07:37:05 所属栏目:MsSql教程 来源:网络整理
导读:1、把主键定义为自动增长标识符类型 在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如: create table customers(id int auto_increment primary key notnull,name varchar(15));insert into customers(name) values("name
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,("name2"); select id from customers; 查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MSSQLServer数据库会自动按递增的方式为主键赋 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |