Skip navigation links

MySQL Forums :: Table Space :: Create Composite Primary Key Errors


Advanced Search

Create Composite Primary Key Errors
Posted by: Robert Walden ()
Date: December 02, 2010 11:09PM

I've been trying unsuccessfully to create a composite primary key. I've tried several different methods, all with the same or similar error messages: "Error 1068 (42000) multiple primary keys defined". (I'm using MySQL "Server version: 5.1.42-community MySQL Community Server (GPL)"). I've tried the following command syntax:


1. To create a composite key at the time of table creation -

CREATE TABLE table1
(key1 CHAR(#),
key2 CHAR(#),
key3 (CHAR(#),
PRIMARY KEY(key1, key2));

2. To create a composite key after-the-fact (no primary key specified when table created) -

ALTER TABLE (tablename)
ADD PRIMARY KEY(key1, key2);

I also tried...

ALTER TABLE (tablename)
ADD PRIMARY KEY(key1);
[and then ran it again for "key2"]

3. I tried not including the key1 and key2 attributes at the time of table creation, and instead using both of the two previous commands (not at the same time) to add the new attribute to the table along with its Primary Key status, as indicated in item 2 above.


All of these methods failed! I read that its definitely possible to do. So, I wonder if there's some bug or problem with my software version that doesn't allow composite keys to be created for some reason?. Has anyone got a clue what's wrong here, or how to fix the problem? I'm relatively new to MySQL.

Thanks!

Options: ReplyQuote


Subject Views Written By Posted
Create Composite Primary Key Errors 7868 Robert Walden 12/02/2010 11:09PM
Re: Create Composite Primary Key Errors 2025 Rick James 12/05/2010 01:22PM


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.