Click here to Skip to main content
11,495,049 members (53,008 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET SQL Server
Hi all,

I have two tables there are parent and child table.and i want to insert data into those tables , firstly i want to insert in parent table and i want to get Identity col value from parent and using this, i want to insert details information into child table.

Here am using stored procedure for inserting data to tables


create table parent(id int primary key,name varchar(40),class varchar(40))
create table child(id int foreign key references parent(id), age int,village varchar(50))

Thanks and Regards,

Dhineshkumar V
Posted 26-Jun-13 4:07am
OriginalGriff at 26-Jun-13 9:27am
What is the problem?
What have you tried? Where are you stuck?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Example sql query:
DECLARE @pid INT --parent id, where id is identity for parent table

INSERT INTO parent ([name], [class])
VALUES('Dhinesh kumar.V', 'last')
INSERT INTO parent (pid, age, village)
VALUES(@pid, 21, 'Best Village')
Have a look here:
Dhinesh kumar.V at 28-Jun-13 5:21am
Thanks buddy...
Maciej Los at 28-Jun-13 6:43am
You're welcome ;)
If your problem is solved, then mark this answer as solved (green button).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 Sergey Alexandrovich Kryukov 350
2 CHill60 318
3 Sascha Lefèvre 280
4 Nakul Chaudhari 236
0 Sergey Alexandrovich Kryukov 10,297
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,864
3 Maciej Los 3,412
4 Richard Deeming 2,500

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100