当前位置: 代码迷 >> SQL >> SQL2K中兑现列的自增
  详细解决方案

SQL2K中兑现列的自增

热度:26   发布时间:2016-05-05 13:47:58.0
SQL2K中实现列的自增
一:数据库的列为整形是,我们可以使用关键字Identity(1,1)实现

二:数据库的列为字符串varchar时,我们仍可实现自增长
create table test001(id nvarchar(10),content varchar(10))go--创建触发器create trigger tg_test001on test001instead of insertasdeclare @content nvarchar(10)select @content= content from insertedinsert into test001(id,content)select cast(isnull(max(id),'0') as int)+1,@contentfrom test001 go--向表中插入数据insert into test001 (content) select 'a'insert into test001 (content) select 'b'go--选择察看插入效果select * from test001go