Jump to content

composite keys in mysql


joebudden

Recommended Posts

Hi guys, does anyone know how to implement a composite key in mysql???

Here are my tables:

[code]
create table player
(
id int not null primary key auto_increment,
name char(30) not null,
surname char(30) not null,
ability int not null,
fitness int not null,
skill int,
position char(1) not null,
prefmove char(100),
description char(100),
teamtalk char(1) not null
);

create table game
(
gameid int not null primary key
);

create table teams
(
id int not null,
gameid int not null,
team char(30),
foreign key (id)
references player(id)
);
[/code]

I want to implement a composite key so that the id's in the teams table are unique where the gameid is the same.

anyone know how to do this ???
Link to comment
https://forums.phpfreaks.com/topic/35152-composite-keys-in-mysql/
Share on other sites

I belive PHP would have to do that whenever accessing the script.  But why do that when you can just renumber them based on their array key after retrieving them if you need them to be numbered 0-whatever.  If you insist on this PHP would have to check and keep a var of what is the highest, looping if($maxid > $dbcurrentid){
//incorrect
}else{
$maxid = $dbcurrentid;
}

after the entire loop $newuserid = $maxid + 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.