i want to insert values in one table then automatically insert in another table using primary and foreign key concept. i am using sql server 2008
i am taking same fields in both table
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 18, 2015, 6:02 AM EST
Best way to do this create a trigger that fire when data insert on your first table. For creating a trigger go through following link.
http://www.tech-recipes.com/rx/41414/sql-server-coding-the-after-insert-trigger-in-sql-server/
http://www.codeproject.com/Articles/25600/Triggers-SQL-Server
Abhishek JaiswalRank #126 · 17.5K reputationPosted Jan 21, 2015, 4:22 AM EST
Just take ref of this..
(
--
DECLARE @totalRecords
SET @totalRecords = 0
DECLARE @currentKey
WHILE @totalRecords < 500
BEGIN
SET @totalRecords = @totalRecords + 1
INSERT INTO
VALUES ('submission record ' + cast
Set @currentKey = Scope_Identity
INSERT INTO
VALUES (@currentKey, 'a new record item for submission '+ cast
END
All the best.