一:数据库的列为整形是,我们可以使用关键字Identity(1,1)实现
二:数据库的列为字符串varchar时,我们仍可实现自增长
二:数据库的列为字符串varchar时,我们仍可实现自增长
create table test001
(
id nvarchar(10),
content varchar(10)
)
go
--创建触发器
create trigger tg_test001
on test001
instead of insert
as
declare @content nvarchar(10)
select @content= content from inserted
insert into test001(id,content)
select cast(isnull(max(id),'0') as int)+1,@content
from test001
go
--向表中插入数据
insert into test001 (content) select 'a'
insert into test001 (content) select 'b'
go
--选择察看插入效果
select * from test001
go