日期:2014-05-19  浏览次数:20677 次

"在SQL创建语句中加上identity,表示自动编号"具体是怎样实现的
"ACCESS的数据库中的自动编号类型在转化时,sql   server并没有将它设为自动编号型,我们需在SQL创建语句中加上identity,表示自动编号 "
上述这段话中提到的 "在SQL创建语句中加上identity,表示自动编号 "具体是怎样实现的
请详细告知
不胜感激

------解决方案--------------------
--Try
CREATE TABLE new_employees
(
id_num int IDENTITY(1,1),
fname varchar (20),
minit char(1),
lname varchar(30)
)

INSERT new_employees
(fname, minit, lname)
VALUES
( 'Karin ', 'F ', 'Josephs ')

SELECT * FROM new_employees

------解决方案--------------------
记得是identity(1,1)前面是起始,后面是种子
------解决方案--------------------
alter table 表名 add id2 int identity(1,1) not null
------解决方案--------------------

一、创建表时,添加自增量:
create table tbl(id int identity,name varchar(10))
二、已存在表时,添加自增列:
alter table tbl add id int identity(1,1)
------解决方案--------------------
创建表table_Pqs,字段id字增,前面的1 种子,后面的1 增量
create table table_Pqs ([id] int identity(1,1),......)
修改表,增加个字增字段
alter table table_Pqs add [id] int identity(1,1)