Hi all :)

Currently now I used MS SQL Server Management Studio 2008.

I have an existing table with data already store on that table.
Table Name :
Application

Column :
Categories (nvarchar(1), null)
Sequence (nvarchar(1), null)
Detail (nvarchar(150), null)

I would like to ask how to add primary key to column Categories and Sequence ?

Thank you in advance !

Re: How to add primary key in existing table 80 80

in Oracle you'd do something like
CREATE UNIQUE INDEX "MYSCHEMA"."MYTABLE_PK" ON "MYSCHEMA"."MYTABLE" ("CATEGORIES", "SEQUENCE")

Of course you could never use the name "SEQUENCE" for a column in Oracle as it's a reserved word (as it is in MS SQL Server, I'm kinda surprised it let you create a column with that name...).

Re: How to add primary key in existing table 80 80

ALTER TABLE Persons
ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)

Re: How to add primary key in existing table 80 80

I have tried but get an error "Cannot define PRIMARY KEY constraint on nullable column in table Application" in SQL Server 2018

commented: Don't hijack old discussions that can't possible apply. 2016 above and you are asking about 2018. Make a new discussion. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.