Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding data to db

Author  Topic 

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-30 : 11:13:42
Hi guys,

this is going to sound like a ridiculous question, but when you are first adding all your records, do you need to add all the foreign key data yourself so that it ties together?

eg. If studentid =1 in first table, then you need to add record for student id in bridging table so that studentid= 1:teacherid=1 and add teacher id=1 if it is not autoincrementing????

Thanks
Cm

svicky9
Posting Yak Master

232 Posts

Posted - 2006-05-30 : 11:27:54
Foreign keys constraints enforce referential integrity.They maintain the relations in a relational database.It

In this case,you can use Triggers or you can use the update cascade.




Vic
Go to Top of Page

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-30 : 11:49:24
This is going to sound dumb, but I thought that when you added data to table 1 and table 3 with a bridging table in between that is connected via foreign keys, that those values would be inserted for you in the bridging table from those values in tables 1 and 3. Is this correct????

Cm
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-30 : 11:57:51
quote:
Originally posted by Chopsmum

This is going to sound dumb, but I thought that when you added data to table 1 and table 3 with a bridging table in between that is connected via foreign keys, that those values would be inserted for you in the bridging table from those values in tables 1 and 3. Is this correct????

Cm



No. There would be no way for SQL Server know how they are related.



CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-05-30 : 12:33:25
Or that sql server would know if YOU wanted to do that

You might want to put data in tableA and tableC but not want to establish a relationship in tableB yet.

"Bridging table"?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-05-30 : 12:34:27
quote:
Originally posted by Chopsmum

If studentid =1 in first table, then you need to add record for student id in bridging table so that studentid= 1:teacherid=1 and add teacher id=1 if it is not autoincrementing????



What if the student isn't taking any courses and has no teachers?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -