Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have a table called provider. I have three columns called a person, place, thing. There can be duplicate persons, duplicate places, and duplicate things, but there can never be a duplicate person-place-thing combination.

How would I ALTER TABLE to add a composite primary key for this table in MySQL with these three columns?

1 Answer

0 votes
by (40.7k points)

Try the code given below:

Query

ALTER TABLE provider ADD PRIMARY KEY(person,place,thing);

If the primary key already exists then you need to use the code as follows:

Query

ALTER TABLE provider DROP PRIMARY KEY, ADD PRIMARY KEY(person, place, thing);

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...