Foreign key relationship with composite primary keys in SQL Server 2005

前端 未结 2 1058
遇见更好的自我
遇见更好的自我 2020-12-01 06:17

I have two tables

Table1(
  FileID,
  BundledFileID,
  Domain)

and

Table2(
  FileID,
  FileType,
  FileName)
2条回答
  •  再見小時候
    2020-12-01 06:30

    marc has already given a pretty good answer. If the rows in Table1 only ever relate to one type of File (e.g. FileType 'ABC'), then you can add FileType to Table1 as a computed column:

    ALTER TABLE Table1 ADD FileType as 'ABC'
    

    Which you can then use in the Foreign Key.

提交回复
热议问题