Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3nf child row population problem 1

Status
Not open for further replies.

schjlatah

Programmer
Dec 14, 2005
3
US
I am new to SQL and have been charged with designing a database in 3NF. I have been having trouble populating rows in the child tables. I can insert into table1 and it will automatically generate the identity column, but how do I populate the child tables with the identity generated by the first table (so as to associate them all together)? Here's a diagram.
dbdiagram.jpg


Is there a better way to do this, am I way out in left field? Any suggestions?
 
declare @id int

insert into table1
values('George','Bush')

select @id =SCOPE_IDENTITY -- or @@identity if you don't have triggers on this table

insert into clientPhone
values (@id ,'1-800-President','999-6666666')


insert into clientaddress
values (@id '1600 Penn Ave','Wash'.....)

of course all this in a nice transaction and checking @@ERROR




Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top