你好我在数据库中有九个表数据库中有两个表是:
tbl_unit
--------
Unit_Number(pk),
Floor_Number(pk),
Apartment_plaque(pk),
BedRoom_Count,
BathRoom_Count,
Rental_Fees_Unit,
Unit_Area,
Unit_state
和
tbl_payment
-----------
Renter_National_Code(pk),
Apartment_Plaque(pk),
Floor_Number(pk),
Unit_Number(pk),
Owner_National_Code,
Payment_Date,
Debt,
Other_Amounts,
Other_amounts_comment,
amount_of_payment
我无法确定tbl_payment中的主键没有作为tbl_unit中主键的外键而且我收到"关系的两边必须具有相同的数字列#34;错误
问题是什么?
答案 0 :(得分:2)
一个表只能有一个主键。您的tbl_payment表具有由4列组成的复合主键,而tbl_unit表具有3列的复合主键。
我相信您希望tbl_payment表上的外键将付款与特定单位相关联。在这种情况下,在引用tbl_units主键的tbl_payment上添加一个3列外键:
ALTER TABLE dbo.tbl_payment
ADD CONSTRAINT fk_tbl_payment_tbl_unit
FOREIGN KEY (
Unit_Number
, Floor_Number
, Apartment_plaque
)
REFERENCES dbo.tbl_unit(
Unit_Number
, Floor_Number
, Apartment_plaque
);