0 votes
1 view
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 (36.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);

...