SQL中先建立一个表,然后想将表的一列设为主键,怎么弄

SQL中先建立一个表,表中有几列,想将表的一列设为主键,怎么用sQL实现?
我使用了
alter table 表名
add constrain primary key(列名)
这样会 提示出错,也不知道是哪里错了

先确定字段属性为“not null”
alter table 表名 alter column 列名 int not null
表内主键字段无重复数据后执行
alter table 表名 add constraint 约束名 primary key(列名)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-28
alter table 表名 add constraint 约束名 primary key (字段)