sql的问题。表2根据表1项自动创建

来源:百度知道 编辑:UC知道 时间:2024/06/19 15:22:47
2张表 test1和test2
分别有列 t1Id和 t2Id
我想让t1Id自动创建编号后,表2中的t2Id也创建编号。并且和t1Id里面的值一样。怎么做。谢谢

创建一个触发器,
脚本为:
create trigger trigger_one on test1
for insert
as
declare @id int
select @id=t1id from inserted
begin
insert into test2(t2id) values(@id)
end

做一个触发器 ,CREATR TRIGGER TRIGGERNAME FOR TABLE