alter table yourtable add ConstaintName primary key(columnName)
/*ConstaintName 数据类型 yourtable 表名 columnName 列名*/
or
create table yourtable(column1 int primary key,....)
--增加列
alter table [TableName] add [P_ID] bigint not null default 0
--删除列
alter table [TableName] drop column [P_ID]
--设置主键
alter table [TableName] add constraint PK_TableName primary key (P_ID)
--删除主键
alter table [TableName] drop constraint PK_TableName
--创建聚集索引(一个表中允许一个聚集索引)
CREATE CLUSTERED INDEX [tTopIndex] ON [TableName] ([P_ID]) ON [PRIMARY]
--创建非聚集索引
CREATE INDEX [tTopIndex] ON TableName ([P_ID]) ON [PRIMARY]
--删除索引
drop index [TableName].[tTopIndex]
--增加字段说明
EXECUTE sp_addextendedproperty N'MS_Description', N'照片ID', N'user', N'dbo', N'table', N'TableName', N'column', N'P_ID'
联合主键
ALTER TABLE jserp.fp WITH NOCHECK ADD
CONSTRAINT [PK_jserp.fp] PRIMARY KEY NONCLUSTERED
(
fp_flid,
fp_fpid
)