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.
Author |
Topic |
tomislavg
Yak Posting Veteran
51 Posts |
Posted - 2010-09-22 : 07:45:13
|
Hi,I have a problem.There are three tables plus one main table. I want to connect these three tables with the Unique Key to the main table.tbl_1 - tbl_1Name_id, tbl_2- tbl_2Name_id, tbl_3 - tbl_3Name_id I want to connect the Name_id fields to the main tbl fields below. main_tbl ___________ tbl_1Name_id tbl_2Name_id tbl_3Name_idMain tbl has a Unique Key for these fields and in the other table, fields they are normal fields NOT NULL. What I would like to do is that any time when the record is entered in tbl_1, tbl_2 or tbl_3, the value from te main tbl shows in that field.Yes and I have the relationship Many to one, one being the main tbl of course.I have a feeling this should be very simple but can not get it to work. |
|
dportas
Yak Posting Veteran
53 Posts |
Posted - 2010-09-26 : 10:26:14
|
Your question isn't very clear to me. When you say you want to "connect" these tables I guess you mean you want a foreign key constraint or constraint(s) between them. Is that correct? If so, which table(s) are supposed to be referencing which other table(s)A foreign key constraint must always reference a candidate key of some other table. It looks to me like you may be getting these constraints "wrong way round", i.e. maybe you should be referencing main_tbl from each of the other tables rather than having three different columns in main_tbl. Here's an example of what I think you may be trying to achieve. Note that in each case it is the key of main that is being referenced, i.e. main is the "one" side of the one-to-many relationships.CREATE TABLE Main (NameID INT NOT NULL PRIMARY KEY);CREATE TABLE Tbl1 (NameID INT NOT NULL REFERENCES Main (NameID), /* PRIMARY KEY ??? */);CREATE TABLE Tbl2 (NameID INT NOT NULL REFERENCES Main (NameID), /* PRIMARY KEY ??? */);CREATE TABLE Tbl3 (NameID INT NOT NULL REFERENCES Main (NameID), /* PRIMARY KEY ??? */); |
|
|
|
|
|
|
|