MYSQL:stuinfo支持加入外键,但是stuinfo1却不可以。stuinfo1支持中文,但是stuinfo却不支持。怎么才能让stuinfo既支持外键也支持。mysql>showcreatetablestuinfo2;+----------+----...
MYSQL:stuinfo支持加入外键,但是stuinfo1却不可以。stuinfo1支持中文,但是stuinfo却不支持。怎么才能让stuinfo既支持外键也支持。
mysql> show create table stuinfo2;
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------------------------------+
| Table | Create Table
|
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------------------------------+
| stuinfo2 | CREATE TABLE `stuinfo2` (
`stuname` varchar(20) DEFAULT NULL,
`stusex` char(1) DEFAULT NULL,
`stuno` char(3) NOT NULL,
PRIMARY KEY (`stuno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------------------------------+
1 row in set (0.00 sec)
mysql> alter table scoreinfo add foreign key (stuno) references stuinfo2(stuno);
ERROR 1005 (HY000): Can't create table 'cq1.#sql-698_2' (errno: 150)
mysql>
mysql> alter table scoreinfo add foreign key (stuno) references stuinfo2(stuno);
ERROR 1005 (HY000): Can't create table 'cq1.#sql-698_2' (errno: 150)
mysql> show create table stuinfo;
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
| Table | Create Table
|
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
| stuinfo | CREATE TABLE `stuinfo` (
`stuname` varchar(20) NOT NULL,
`stusex` char(1) DEFAULT NULL,
`stuno` char(3) NOT NULL DEFAULT '',
PRIMARY KEY (`stuno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+---------+---------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------+
1 row in set (0.00 sec)
展开