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

如何使一个列的值自动加1
我是刚刚接触MS-SQL的,在文档里面找了很久,没有找到这个函数,使列自动增一,在MySQL里有这个函数,不知道这里该怎么实现,请各位高手指点一下!!
谢谢!!!

------解决方案--------------------
create table a(a int identity(1,1))
------解决方案--------------------
eg:

Create Table TEST
(ID Int Identity(1,1),
Name Varchar(10))
------解决方案--------------------
create table tb1(sn int identity(1,1),name1 char(8));
------解决方案--------------------
create table t(id int identity(1,1),code varchar(4))
insert into t(code) select 'AAAA '
insert into t(code) select 'BBBB '
insert into t(code) select 'CCCC '
go

select * from t
go

drop table t

------解决方案--------------------
create table t(id int identity(1,1),code varchar(4))
insert into t(code) select 'AAAA '
insert into t(code) select 'BBBB '
insert into t(code) select 'CCCC '
go

select * from t
/*
id code
----------- ----
1 AAAA
2 BBBB
3 CCCC
*/
go

drop table t
go