ALTER TABLE distributors ADD PRIMARY KEY (dist_id)dist_id为新增字段。
alter table table1 alter column id int not nullALTER TABLE [dbo].[table1] WITH NOCHECK ADD CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED ( [id] ) ON [PRIMARY]
to merkey2002(小样的) : alter table student drop constraint pk_student --去掉这个表的主键 这个语句不能实现删除主键,出错提示: Server: Msg 3728, Level 16, State 1, Line 1 ‘pk_student‘ is not a constraint. Server: Msg 3727, Level 16, State 1, Line 1 Could not drop constraint. See previous errors.
drop constraint pk_student
--去掉这个表的主键alter table student
add constraint pk_student primary key clustered (studentid, seq)
--重新设置表的主键
CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
--去掉这个表的主键 这个语句不能实现删除主键,出错提示: Server: Msg 3728, Level 16, State 1, Line 1
‘pk_student‘ is not a constraint.
Server: Msg 3727, Level 16, State 1, Line 1
Could not drop constraint. See previous errors.