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?

4

1 回答 1

1

这种关系在 sql 中很常见,但是你通常以一种不需要更新第二张表的方式来构建它,即在每个表中使用 id 来表示它们的值,并且当更改变量值时,您不必更新多个表。

例如:

如果你有一张桌子

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

和桌吧

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)
);

这样,当您在表 foo 上将 bob 的名称更改为 john 时,您不必更改表 bar 上的任何内容,因为您引用的是 id 字段而不是名称。

希望能帮助到你。

于 2013-08-04T00:11:26.433 回答