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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 FK question

Author  Topic 

merrittr
Starting Member

10 Posts

Posted - 2014-09-09 : 18:38:38
I have a database with a section with a hierarchy like this:
[url]http://www.merrittnet.org/pics/original.JPG[/url]

here everything is linked off the tblTumorSupplemental table

what i am being asked to now leads me to this

[url]http://www.merrittnet.org/pics/after.JPG[/url]

where I add a FK in the tblTumorSupplComps and tblTumorSupplMets
to link to the PK of tblTumorSupplSourceDocuments by adding



ALTER TABLE tblTumorSupplMets
ADD TumorSupplSourceDocumentsId int NULL
GO
ALTER TABLE tblTumorSupplComps
ADD TumorSupplSourceDocumentsId int NULL
GO

ALTER TABLE tblTumorSupplMets
ADD CONSTRAINT FK_tblTumorSupplSourceDocuments_tblTumorSupplMets FOREIGN KEY (TumorSupplSourceDocumentsId)
REFERENCES tblTumorSupplSourceDocuments(TumorSupplSourceDocumentsId);

GO

ALTER TABLE tblTumorSupplComps
ADD CONSTRAINT FK_tblTumorSupplSourceDocuments_tblTumorSupplComps FOREIGN KEY (TumorSupplSourceDocumentsId)
REFERENCES tblTumorSupplSourceDocuments(TumorSupplSourceDocumentsId);

GO


is this valid or am I causing myself grief...is it valid to have null FK in the tables like I will have for previous records in
tblTumorSupplComps and tblTumorSupplMets
   

- Advertisement -