Create primary key in a table that already exists in sqlserver

Asked

Viewed 15,857 times

4

I imported a file txt with six million lines for a Sqlserver table.

Now I want to create a primary key in it, the problem is that no column guarantees integrity, so I want to create another column with auto increment.

How would I do that?

1 answer

4


To generate the column just do the following:

First create a column with auto increment:

alter table TABELA
add id [bigint] IDENTITY(1,1)

Then turn this column into a primary key.

ALTER TABLE TABELA
ADD CONSTRAINT pk_NOME PRIMARY KEY (id)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.