在ACCESS中有定义好的自动编号类型,使用方便。有人咨询我,在SQL Server中是没有的,我们该怎么做呢?
其实很简单,使用sqlsever2005的管理管理工具(2000下是企业管理器),只需要定义成整型int,在该属性字段的“列属性”里找到“标识”,是否选择标识,选择“是”,再定义增量种子1。
sql语句又怎么写呢?只需在int 后面家“identity(1,1)”,例如,我们建个三维位置表location代码如下:
create table location(
id int identity(1,1) not null primary key,
x float not null,
y float not null,
z float not null,
)