| Author |
Topic |
|
merwyn007
Starting Member
4 Posts |
Posted - 2009-03-30 : 14:06:00
|
| hi im new to sql i just want the syntax for trigger in which whenever a data is added in parent table automatically that data is entered through this trigger.pls help as i will be implementing in project soon.merwyn |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
merwyn007
Starting Member
4 Posts |
Posted - 2009-03-31 : 00:57:54
|
| hi Sir i want to add the data through trigger in child table. i want the syntax for trigger, as for this query u gave me Sir is that i have to run this query everytime when i insert data in parent table.pls help Sirmerwyn |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-04-01 : 01:38:57
|
| Yes Read Books Online on Sql Server to Create a Trigger on Insert,,,in This When you Insert a New Value in Ur Parent Table then this trigger fire automatically.. n update the value in your child table also,,,something likeCREATE TRIGGER YourTriggerNameON YourTableAFTER INSERT AS BEGINUPDATE tSET t.yourfield=(SELECT yourfield FROM Table)FROM Table tINNER JOIN INSERTED iON i.PK=t.PKENDPk Is Primary Key Of your Table,,,, |
 |
|
|
merwyn007
Starting Member
4 Posts |
Posted - 2009-04-01 : 05:52:00
|
| hi this the query for updateI want to create a trigger such that when I insert a item it should insert one row in another table with same item codemerwyn |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-04-01 : 06:06:26
|
| Sorry Then Use This As Above TAra Stated ,,,,CREATE TRIGGER YourTriggerNameON YourTableAFTER INSERT AS BEGININSERT INTO SomeTable (...)SELECT ... FROM insertedENDMay BE like This,,,Or Show us what will u try till now....Thanks,,,, |
 |
|
|
merwyn007
Starting Member
4 Posts |
Posted - 2009-04-01 : 06:23:07
|
| hi this my querymy table defination isItemEJBTable(itemCode int primary key,itemDescription varchar(50))Vote_Info(itemCode int foreign key references ItemEJBTable , Number_Votes int)CREATE TRIGGER TItemCodeON ItemEJBTableAFTER INSERTASBEGININSERT INTO Vote_Info(itemCode,0)SELECT itemCode FROM insertedENDnow how to solve this im in great trouble nowmerwyn |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-04-01 : 07:00:18
|
| it works perfectly fine for me...CREATE TRIGGER [ashuaaa] ON [dbo].[emp] AFTER INSERTAS BEGIN SET NOCOUNT ON;INSERT INTO emp1(sal)SELECT sal FROM insertedENDGO |
 |
|
|
|