jak powiązać tabele

0

Witam chce połączyć dwie tabele poprzez class i id

mysql> DESCRIBE student;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(11)     | NO   | PRI | NULL    | auto_increment |
| name    | varchar(30) | YES  |     | NULL    |                |
| surname | varchar(30) | YES  |     | NULL    |                |
| class   | int(11)     | YES  |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
mysql> desc class;
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| name_class | varchar(15) | YES  |     | NULL    |                |

użyłem ALTER TABLE CHANGE COLUMN class CONSTRAINT FOREIGN KEY (class) REFERENCES class(id) ale wyskakuje mi błąd.

1
ALTER TABLE student add CONSTRAINT FOREIGN KEY (class) REFERENCES class(id)

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0