Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn existing column into a primary key

Tags:

sql

sql-server

create table emp
 (
 emp_id int,
 emp_name varchar(40) not null,
 emp_address varchar(35) not null,
 )

Now I need to add primary key to emp_id . I tried using alter query

alter table emp add constraint   emp_id  primary key

its showing error as

Table level constraint does not specify column list, table 'emp'.

like image 325
Logeshwaran Veluchamy Avatar asked Apr 15 '14 05:04

Logeshwaran Veluchamy


1 Answers

ALTER TABLE emp
ADD PRIMARY KEY (emp_id)

OR

ALTER TABLE emp
ADD CONSTRAINT pk_empID PRIMARY KEY (emp_id)
like image 108
Brij Raj Singh - MSFT Avatar answered Nov 13 '22 10:11

Brij Raj Singh - MSFT