2011-09-23 39 views

回答

5

create table X 
(
    c int primary key 
) 

create table Y 
(
    c bit references X 
) 

返回:

Msg 1778, Level 16, State 0, Line 1
Column 'X.c' is not the same data type as referencing column 'Y.c' in foreign key 'FK__Y__c__34C8D9D1'. Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

另見the relevant section in BOL

  • 列級FOREIGN KEY約束只能 列表中的一個參考列的REFERENCES子句。此列必須與定義約束的列具有相同的數據類型 。

  • 表級FOREIGN KEY約束必須 的REFERENCES子句具有相同數量的參照列中 約束列列表中的列數。每個參考列 的數據類型也必須與列列表中的相應列相同。