0 votes
1 view
in SQL by (22.4k points)

I have an existing table called Persion. In this table I have 5 columns:

  • persionId
  • Pname
  • PMid
  • Pdescription
  • Pamt

When I created this table, I set PersionId and Pname as the primary key.

I now want to include one more column in the primary key - PMID. How can I write an ALTER statement to do this? (I already have 1000 records in the table)

1 Answer

0 votes
by (72.1k points)

First, drop the constraints of the table and create the new primary constraint to the table

-- Drop the existing primary key constraints

ALTER table Persion 

DROP CONSTRAINT 

PK_persionId

-- Create new primary key constraints

ALTER table Persion 

ADD primary key (persionId, Pname, PMID)

I recommend this SQL Certification course by Intellipaat to learn SQL from Industry experts.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...