我首先创建了教师表,它的描述是
mysql> desc teacher;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| TEACHER_ID | varchar(3) | NO | PRI | NULL | |
| TEACHER_NAME | varchar(40) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
在我创建了一个如下的新表之后。我的需要是在下表中我想TEACHER_ID
用作外键。我写了以下内容。我不知道它是否在语法上是错误的。但我没有得到任何错误...
mysql> CREATE TABLE SUB_MCA_TY
-> (SUB_ID VARCHAR(4) PRIMARY KEY,
-> SUB_NAME VARCHAR(30),
-> TEACHER_ID VARCHAR(3) REFERENCES TEACHER(TEACHER_ID));