日期:2014-05-18  浏览次数:20871 次

一个关于组合外键的问题!
Create Table Zadb.dbo.GX_GPHZ_BAK2008
(
Yyyymm Char (6) Not Null ,
Type Char (1) Default '' ,
GpdNo Numeric (7) Not Null
Constraint GX_GPHZ_BAK2008_PK Primary Key(Yyyymm,Gpdno)
)

Create Table Zadb.dbo.GX_GPMX_BAK2008
(
Yyyymm Char (6) Not Null ,
GpdNo Numeric (7) Not Null ,
TxmNo Char (20) Default '' ,
Gx_no Char (2) Not Null
Constraint GX_GPMX_BAK2008_PK Primary Key(Yyyymm,Gpdno,Gx_no)
Constraint GX_GPMX_BAK2008_FK Foreign Key(Yyyymm,Gpdno) References Zadb.dbo.GX_GPHZ_BAK2008(Yyyymm,Gpdno)
)

结果建表时出现这句话:

消息 8140,级别 16,状态 0,第 9 行
在表 'Zadb.dbo.GX_GPMX_BAK2008' 的列级别 FOREIGN KEY 约束中指定了多个键。

我看SQLSERVER语法是允许建组合外键的,但为什么会出现这情况。请高手帮忙看看。




------解决方案--------------------
Constraint GX_GPMX_BAK2008_PK Primary Key(Yyyymm,Gpdno,Gx_no), <--这里少了个逗号
Constraint GX_GPMX_BAK2008_FK Foreign Key(Yyyymm,Gpdno) References Zadb.dbo.GX_GPHZ_BAK2008(Yyyymm,Gpdno)