sql server中如何实现自增字段?

如题所述

第1个回答  2019-07-17
SQL
Server
自增主键创建语法:
identity(seed,
increment),其中为seed
起始值,increment
为增量。示例如下:
create
table
student

//创建学生表
(id
int
identity(1,1),

name
varchar(100)


//
id字段为自增
自增字段的类型必须为不带小数的数值类型。
扩展资料:
实现自增字段的其他方法:
下列
SQL
语句把
"Persons"
表中的
"P_Id"
列定义为
auto-increment
主键:
CREATE
TABLE
Persons
(
P_Id
int
NOT
NULL
AUTO_INCREMENT,LastName
varchar(255)
NOT
NULL,
FirstName
varchar(255),
Address
varchar(255),
City
varchar(255),PRIMARY
KEY
(P_Id)

参考资料:搜狗百科-标识列
相似回答
大家正在搜