首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL2K中兑现列的自增

2012-09-17 
SQL2K中实现列的自增一:数据库的列为整形是,我们可以使用关键字Identity(1,1)实现二:数据库的列为字符串va

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

热点排行