读书人

SQL2K中兑现列的自增

发布时间: 2012-09-17 12:06:51 作者: rapoo

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

读书人网 >SQL Server

热点推荐