Foreign key from bit to int
Is it possible to create a fore开发者_如何学JAVAign key where type of the first column is bit but type of the referenced column is int?
No.
create table X
(
c int primary key
)
create table Y
(
c bit references X
)
Returns:
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.
Also see the relevant section in BOL:
The
REFERENCES
clause of a column-levelFOREIGN KEY
constraint can list only one reference column. This column must have the same data type as the column on which the constraint is defined.The
REFERENCES
clause of a table-levelFOREIGN KEY
constraint must have the same number of reference columns as the number of columns in the constraint column list. The data type of each reference column must also be the same as the corresponding column in the column list.
精彩评论