sqlserver设置主键并且排列

Alter table TABLENAME alter column COLUMN_NAME INT not null 
ALTER TABLE TABLENAME ADD  CONSTRAINT [PK_TABLENAME] PRIMARY KEY CLUSTERED 
(
	[COLUMN_NAME] ASC
)
ON [PRIMARY]



添加外键
ALTER TABLE [dbo].[USER_ACCOUNT]  WITH CHECK ADD  CONSTRAINT [FK_USER_ACCOUNT_REGION] FOREIGN KEY([REGION_ID])
REFERENCES [dbo].[REGION] ([REGION_ID])

你可能感兴趣的:(sql)