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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhishek JaiswalPosted Jan 21, 2015, 9:22 AM
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.
Manish Kumar ChoudharyPosted Jan 18, 2015, 11:02 AM
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