|
|
|
| Добрый день, я хотел бы узнать как можно связать таблицы в базе данных Mysql
У меня следующие таблицы:
direction
type
unit
Сейчас я хочу создать новую таблицу main которая должна содержать поля:
create table main (mainid int(10) not null auto_increment,
dirid int(10) not null, typeid int(10) not null,
price int(10) not null,
unitid(10) not null,
primary key (mainid),
CONSTRAINT FOREIGN KEY (dirid) REFERENCES direction (dirid) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (typeid) REFERENCES type (typeid) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (unitid) REFERENCES unit (unitid) ON DELETE RESTRICT ON UPDATE CASCADE );
Проблема собственно в синтаксисе подскажите пожалуйста где, что нужно исправить?
direction:
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| dirid | int(10) | NO | PRI | NULL | auto_increment |
| dirname | varchar(50) | NO | | NULL | |
+---------+-------------+------+-----+---------+----------------+
type:
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| typeid | int(10) | NO | PRI | NULL | auto_increment |
| typename | varchar(50) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
unit:
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| unitid | int(10) | NO | PRI | NULL | auto_increment |
| unitname | varchar(50) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
Спасибо... | |
|
|
|
|
|
|
|
для: oleg9999
(19.08.2009 в 12:39)
| | Возможно нужно явно указать тип таблицы InnoDB
, если тип по умолчанию MyISAM
я так думаю
unitid(10) not null,
здесь опечатка | |
|
|
|