joebudden Posted January 22, 2007 Share Posted January 22, 2007 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 More sharing options...
mattd8752 Posted January 22, 2007 Share Posted January 22, 2007 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 Link to comment https://forums.phpfreaks.com/topic/35152-composite-keys-in-mysql/#findComment-165992 Share on other sites More sharing options...
joebudden Posted January 22, 2007 Author Share Posted January 22, 2007 hmmm i dont really understand your answer, could u please explain it..so is it not possible to implement a composite key ? Link to comment https://forums.phpfreaks.com/topic/35152-composite-keys-in-mysql/#findComment-165999 Share on other sites More sharing options...
joebudden Posted January 22, 2007 Author Share Posted January 22, 2007 anyone??? Link to comment https://forums.phpfreaks.com/topic/35152-composite-keys-in-mysql/#findComment-166014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.