开发者

sql server 2008 composite key

开发者 https://www.devze.com 2022-12-18 08:58 出处:网络
How to set a field as a composite key in sql server 2008 and how to create开发者_运维百科 a composite key in gui sql server 2008? You can\'t set \"one field\" as a composite key - by definition, \"com

How to set a field as a composite key in sql server 2008 and how to create开发者_运维百科 a composite key in gui sql server 2008?


You can't set "one field" as a composite key - by definition, "composite" means more than one.

In SQL Server Management Studio, you can highlight more than one column in the table designer, and choose "Set Primary Key" from the context menu:

sql server 2008 composite key

That makes those selected columns a composite primary key.


Here is an example in T-SQL. The first two columns comprise the composite key. In SSMS, just highlight the first columns you want to comprise the key and select the Primary Key button on the toolbar.

CREATE TABLE [Security].[MemberRole](
        [MemberID] [int] NOT NULL,
        [RoleID] [int] NOT NULL,
        [VersionNumber] [timestamp] NOT NULL,
CONSTRAINT [PK_MemberRole] PRIMARY KEY CLUSTERED 
(
        [MemberID] ASC,
        [RoleID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
0

精彩评论

暂无评论...
验证码 换一张
取 消