Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k 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 (119k points)
edited by

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 



-- Create new primary key constraints

ALTER table Persion 

ADD primary key (persionId, Pname, PMID)

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

Related questions

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

30.5k questions

32.5k answers


108k users

Browse Categories