Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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 

DROP CONSTRAINT 

PK_persionId

-- 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!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...