本文介绍了如何在SQL Server 2005的现有表中添加主键(查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我已经在sql编辑器上执行了以下查询

Hello

i have execute the following query on sql editor

create database Employee
use Employee
create table Emp
(
id integer,
E_Name nvarchar (20),
e_Add nvarchar(50)
)
select * from Emp
insert into Emp values('001','Reshma','BBSr')



所以我想在现有表Emp
上添加一个主键我在sql编辑器上写了以下查询



so i want to add a primary key on existing table Emp
i have write the following query on sql editor

alter table Emp add constraint pk_Emp primary key(id)


但执行上述查询后

将出现以下错误



but after execute the of the above query

the following error will be raised


Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table 'Emp'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.



因此,请尽可能向我建议ASAP



So how it can possible please suggest me ASAP

推荐答案



这篇关于如何在SQL Server 2005的现有表中添加主键(查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:14
查看更多