Sql server 2008 为什么执行sql脚本会在设计视图中显示不同的约束
我在SQLServerManagementStudio中执行了以下脚本Sql server 2008 为什么执行sql脚本会在设计视图中显示不同的约束,sql-server-2008,ssms,Sql Server 2008,Ssms,我在SQLServerManagementStudio中执行了以下脚本 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(Permi
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?
为了方便起见,附加了快照
在设计视图中,只有主键列由键标记,
外键未标记。也可以查看表中的所有键,在对象资源管理器中左键单击表,它将显示一个名为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)
)