我在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被视为主键。为什么不考虑权限ID?
为方便起见,附加了快照
答案 0 :(得分: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)
)