【发布时间】:2016-02-07 18:01:58
【问题描述】:
例如
create table Equipment (
Equipmenttype nvarchar(1,
Description nvarchar(10),
Primary Key (Equipmenttype)
)
Create table Room (
RoomID nvarchar(8),
Capacity numeric(3),
Roomtype(fk,nvarchar(2)
)
我要创建下表...
create table RoomEquipment(
(RoomID here)
(Equipmenttype here)
但Equipmenttype 不是主键。
【问题讨论】:
-
没有。您不能为任何列创建外键。这没有任何逻辑意义。当然,在您的示例中,您声明 EquipmentType 是主键。
-
我看到 Equipmenttype id PK。 RoomID 不是 PK。
-
如果你想这样做,那么你已经在你的数据库设计中发现了一个缺陷。
-
不需要 pk,备用键(唯一约束)也可以工作。
-
任何表都应该包含一个PK,因为你的查询的性能已经
标签: sql sql-server sql-server-2008