SQL Server 创建表复合主键

复合主键,即多个字段标识唯一性,只要不是复合主键每个值都重复,就不算重复。

USE TestDB;
GO

IF EXISTS(SELECT * FROM sysobjects WHERE [name]='Users')
	DROP TABLE [Users]
GO
CREATE TABLE [Users](
	[Id] [int] IDENTITY (1,1),
	[UserName] [varchar](50),
	[FullName] [nvarchar](50),
	CONSTRAINT [PK_Users] PRIMARY KEY ([UserName], [FullName])
);


热门推荐