Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to adding the primarey key on table column

Author  Topic 

sandeep1209
Starting Member

6 Posts

Posted - 2012-03-09 : 00:49:24
Hi Friends,

I'm trying to adding the primarey key on table column. table having 7 numbers of rows,


Any one can tell me how to primarey key on table.

EX:
create table index1 (eno int,ename varchar(20),sal money)
insert index1 values(105,'ajay',9000),(103,'akil',8000),(101,'ajay',7000),(102,'ram',8500),(104,'vinad',9200)

-- now i'm trying to give not null constraint and primarey key
alter table index1 alter column eno int not null

i got the following result
ALTER TABLE ALTER COLUMN eno failed because one or more objects access this column.

Thank's
Sandeep

sandeep

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-09 : 03:19:14
Drop any indexes or constraints that are defined on that column first.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -