1

IS it a way to merge a variable called "bob" in the table foo, with my variable bob2 in my table foo2?

so they match eachother all the times.

Since im updating "bob". i want if that value changes, it also does to bob2, and vise versa.

Is this possible?

EDIT:

CREATE TABLE IF NOT EXISTS `stats` (
  `ID` int(11) NOT NULL auto_increment,
  `player` varchar(12) default '',
  `rank` varchar(12) default '',
  `winpot` int(20) default '0',
  `gamesplayed` int(11) default '0',
  `tournamentsplayed` int(11) default '0',
  `tournamentswon` int(11) default '0',
  `handsplayed` int(11) default '0',
  `handswon` int(11) default '0',
  `bet` int(11) default '0',
  `checked` int(11) default '0',
  `called` varchar(11) default '0',
  `allin` varchar(11) default '0',
  `fold_pf` varchar(11) default '0',
  `fold_f` varchar(11) default '0',
  `fold_t` varchar(11) default '0',
  `fold_r` int(11) default '0',
  PRIMARY KEY  (`ID`)
  FOREIGN KEY (winpot) REFERENCES brukere(hand)
);

error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (winpot) REFERENCES brukere(hand) )' at line 20

im trying to get winpot reference to hand in the table brukere.

What is wrong here?

edit2:

create table brukere(
  hand int(20) NOT NULL,
  id int(20) NOT NULL auto_increment,
  PRIMARY KEY (id)
  );

CREATE TABLE IF NOT EXISTS `stats` (
  `ID` int(11) NOT NULL auto_increment,
  `player` varchar(12) default '',
  `rank` varchar(12) default '',
  `winpot` int(20),
  `gamesplayed` int(11) default 0,
  `tournamentsplayed` int(11) default 0,
  `tournamentswon` int(11) default 0,
  `handsplayed` int(11) default 0,
  `handswon` int(11) default 0,
  `bet` int(11) default 0,
  `checked` int(11) default 0,
  `called` varchar(11) default '0',
  `allin` varchar(11) default '0',
  `fold_pf` varchar(11) default '0',
  `fold_f` varchar(11) default '0',
  `fold_t` varchar(11) default '0',
  `fold_r` int(11) default 0,
  PRIMARY KEY  (`ID`),
FOREIGN KEY (winpot) REFERENCES brukere(hand)
);

Schema Creation Failed: Can't create table 'db_2_7249b.stats' (errno: 150): 

( could not upload trought SQL ( still looking into that) . so posted it here. Hope you dont mind

what is wrong here?

2
  • 4
    You're most likely doing this wrong, look into foreign keys to do this kind of relation. Commented Aug 3, 2013 at 23:39
  • You're missing a comma after the primary key. Commented Aug 4, 2013 at 1:20

1 Answer 1

1

That kind of relation is very common in sql, but you usually build it in a way that you don't have to update the second table, i.e., you use id's in each table to represent their values, and when change the variable values, you don't have to update multiple tables.

For example:

If you have a table foo

CREATE TABLE foo (
     id integer NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
);

and table bar

CREATE TABLE bar (
     id INTEGER NOT NULL AUTO_INCREMENT,
     foo_id INTEGER NTO NULL,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id),
     FOREIGN KEY (foo_id) REFERENCES foo(id)
);

This way, when you change the name of bob to john on table foo, you don't have to change anything on table bar, since you have the reference to the id field and not the name.

Hope it helps.

Sign up to request clarification or add additional context in comments.

24 Comments

Thank you! is this working from foo1 to foo too? or do i need to have that code in the table foo too? :P anyway, will try this!
CREATE TABLE IF NOT EXISTS stats ( ID int(11) NOT NULL auto_increment, player varchar(12) default '', rank varchar(12) default '', winpot int(20) default '0', gamesplayed int(11) default '0', fold_r int(11) default '0', FOREIGN KEY (winpot) REFERENCES brukere(hand) PRIMARY KEY (ID) ); what is wrong?
You have some syntax errors and you have to create the table brukere first. See this fiddle
my hand is hand bigint(255) but still getting those errors.
Sorry, i don't. And i'm afraid i can't help you on this. You'll have to go through your tables and check for foreign keys associated with your brukere table. If you run into some specific problems, feel free to post another question. Regarding this one, if you feel this answer helped you, don't forget to accept it and maybe vote up.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.