SQL帮助(复制和更改ID) [英] sql help ( duplication and change id)
问题描述
id plan_id名称状态
1 1 1A 1
2 1 2A 1
3 1 3A 1(表1)
4 2 1A 1
5 2 2A 1
6 2 3A 1
--------------------------------------------
id plan_id日期
1 1 12/03/2012(表2)
2 2 13/03/2012
我想在第2个故事中添加新的plan_id时在表1中添加行.请帮助我如何做..
id plan_id name status
1 1 1A 1
2 1 2A 1
3 1 3A 1 (table 1)
4 2 1A 1
5 2 2A 1
6 2 3A 1
--------------------------------------------
id plan_id date
1 1 12/03/2012 (table 2)
2 2 13/03/2012
i want to add rows in table 1 whenever i add new plan_id in tale 2. pls help me how to do it..
推荐答案
在表2上添加一个触发器,该触发器将在表1中插入一行
add a trigger on table 2 which will insert a row in table 1
CREATE TRIGGER <Schema_Name, sysname, Schema_Name>.<Trigger_Name, sysname, Trigger_Name>
ON <Schema_Name, sysname, Schema_Name>.<Table_Name, sysname, Table_Name>
AFTER <Data_Modification_Statements, , INSERT>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
END
创建将解决您问题的触发器
一切顺利
Create Triggers that will solve your problem
All the best
这篇关于SQL帮助(复制和更改ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!