This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes MySql primary keys Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "MySql primary keys" Watch "MySql primary keys" New topic
Author

MySql primary keys

Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
Now, I know this isn't quite JDBC but...

I'm trying to create a table in MySql with 2 columns as the primary key. I tried this:
create table workout (
userId varchar(32) primary key,
workoutId mediumint primary key,
workoutDate date,
workoutType tinyint,
creationDate date,
lastUpdateDate timestamp,
lastUpdateUserId varchar(32) )
type=InnoDB;
but it didn't work...
Any suggestions?
ms


ms<br />SCJP, SCJD
Simon Havenith
Greenhorn

Joined: Mar 01, 2004
Posts: 4
How about :
create table workout (
userId varchar(32) ,
workoutId mediumint,
workoutDate date,
workoutType tinyint,
creationDate date,
lastUpdateDate timestamp,
lastUpdateUserId varchar(32),
PRIMARY KEY (userId,workoutId)) ;
Cheers
[ March 01, 2004: Message edited by: Simon Havenith ]
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
thanks it worked (once I NOT NULL'ed the columns)
ms
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: MySql primary keys
 
Similar Threads
jdbc-sql
Hibernate: Found two representations of same collection
Exception in Deleting Parent and Child entity
sequence generator with mysql
How to model a relation where a column has to refer two columns in different tables?