0

我在 sql server management studio 中执行了以下脚本。

create table Accounts_RolePermissions
(
    RoleID int not null,
    PermissionID int not null,
    Primary key(RoleID,PermissionID),
    Foreign key(RoleID) references Accounts_Roles(RoleID),
    Foreign key(PermissionID) references Accounts_Permissions(PermissionID)
)

但是当单击表上的设计选项时,它显示只有 RoleID 被视为主键。为什么不考虑 Permission ID ? 为方便起见附上快照 在此处输入图像描述

4

1 回答 1

0

只有主键列由设计视图中的键标记,foreign keys are not marked。也可以查看表中的所有键,在对象资源管理器中左键单击表,它会显示一个名为 Key 的文件夹,打开此文件夹,它将显示此表的所有键。
在您的情况下,我认为问题是由外键引起的,如果您在没有外键的情况下运行查询,它会将您的两列都显示为主键。我测试了它

create table Accounts_RolePermissions
(
  RoleID int not null,
  PermissionID int not null,
  Primary key(RoleID,PermissionID),
--Foreign key(RoleID) references Accounts_Roles(RoleID),
--Foreign key(PermissionID) references Accounts_Permissions(PermissionID)
)
于 2012-08-14T18:18:05.767 回答