你直接设计表的时候用identity不行了吗 你说的这个,也可以实现,但有很多种情况。你如果一次插入一条数据,用下面的这个触发器就行。 create table jx(id int,name nvarchar(10))insert jx select 1,N'张三' insert jx select 2,N'李四' --创建触发器 create trigger t_ins on jx for insert as update jx set id=(select max(id) from jx)+1 where id is null--插入测试数据 insert jx(name) select N'礼拜'
你说的这个,也可以实现,但有很多种情况。你如果一次插入一条数据,用下面的这个触发器就行。
create table jx(id int,name nvarchar(10))insert jx select 1,N'张三'
insert jx select 2,N'李四'
--创建触发器
create trigger t_ins on jx for insert
as
update jx set id=(select max(id) from jx)+1 where id is null--插入测试数据
insert jx(name) select N'礼拜'