CREATE TRIGGER 名 on 表
INSTEAD OF INSERT
AS
BEGIN
if (select max(left(a,8)) from table1 where left(a,8)=(select convert(varchar(8),getdate(),112)))is null
begin
insert into table1(a)
select convert(varchar(8),getdate(),112)+'-0001'
end
else
if (select left(max(a),8) from table1)>=(select convert(varchar(8),getdate(),112))
begin
insert into table1(a)
select convert(varchar(8),getdate(),112)+'-'+
(select right(cast(max(right(a,4))as int)+10001,4)as a from table1
where left(a,8)=(select convert(varchar(8),getdate(),112)))
end
else
begin
insert into table1(a)
select convert(varchar(8),getdate(),112)+'-0001'
end
END
CREATE TRIGGER 名 on 表
INSTEAD OF INSERT
AS
BEGIN
INSERT INTO 表
SELECT name1,name1
FROM inserted
END