MySQL Forums
Forum List  »  Newbie

Re: Problem creating table with 2 primary keys
Posted by: Keith Larson
Date: June 17, 2013 09:03PM

It will not let you because you have a Primary Key and a Unique key.

I was curious if that was what you really wanted.

You stated you wanted 2 Primary keys, and you can have one.
A primary key has to be unique.
You can also create a unique key across different values or make another field be Unique, which we did
PRIMARY KEY (album_id) ,
UNIQUE KEY `aid` (`artist_id`)

So you want a KEY (assuming you plan on needing it) and a Primary key
drop table album;
CREATE TABLE album (
album_id INT (4) NOT NULL AUTO_INCREMENT,
artist_id INT(5) NOT NULL,
album_name varchar(128) DEFAULT NULL,
PRIMARY KEY (album_id) ,
KEY `aid` (`artist_id`)
);

This will allow you to enter 1 album ID and more than 1 artist id.

Just trying to help....

http://anothermysqldba.blogspot.com

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.