Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

i have execute the following query on sql editor

SQL
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')


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

SQL
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.


So how it can possible please suggest me ASAP
Posted
Updated 28-Oct-11 1:26am
v3

To fix this this case all columns over which the PRIMARY KEY constraint should be declared needs to be explicitly created as NOT NULL. Give a try and let us know.
 
Share this answer
 
yes i have done Thank u for sending me a response
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900