2
是否有可能創建一個外鍵,其中第一列的類型是位,但被引用列的類型是int?從位到int的外鍵
是否有可能創建一個外鍵,其中第一列的類型是位,但被引用列的類型是int?從位到int的外鍵
號
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
子句具有相同數量的參照列中 約束列列表中的列數。每個參考列 的數據類型也必須與列列表中的相應列相同。