哪位高手能给发一些有关MySQL中建立外键约束的详细介绍资料,本人在table中建立外键约束时总是提示同一个错误“ERROR 1005 (HY000): Can't create table 'xxx' (errno: 121)”,不知该如何解决,因此在建table时,不敢加外键约束,在网上收了很久都没找到有关的详解,很是苦恼。
还请各位高人给予指教!
还请各位高人给予指教!
解决方案 »
- [菜鸟在线等]
- 把一台服务器上的一个库里的一张表用语句insert导另一台服务器上的一个库里,如何做到?
- 【请教】mysql 插入数据如何转义分号
- DatabaseMetaData.getTables()方法得到oracle所有用户创建的表
- Mysql数据库中怎样快速查询符合条件的记录是否存在
- 完全支持POSTGRESQL的EBB论坛2.1版提供下载
- 我是新手,请帮忙啊!
- mysql里字符集的一些事
- 寻求合理的虚拟主机,支持asp+ms sql或着php+mysql,要求价格公道。
- 关于数据库名称是中文的问题
- mysql_query(&zhqy,"select * from shop")时 报错Commands out of sync
- outport命令导出sql文件里面的问题??
用的什么存储引擎?
-> id int primary key,
-> col int
-> )engine=innodb;
Query OK, 0 rows affected (0.09 sec)mysql> create table t2 (
-> id int primary key,
-> tid int,
-> FOREIGN KEY (tid) REFERENCES t1(id)
-> )engine=innodb;
Query OK, 0 rows affected (0.09 sec)mysql> insert into t2 values (2,1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`csdn`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`tid`) REFERENCES `t1` (`
id`))
mysql> insert into t2 values (1,null);
Query OK, 1 row affected (0.05 sec)mysql> insert into t1 values (1,91);
Query OK, 1 row affected (0.06 sec)mysql> insert into t2 values (2,1);
Query OK, 1 row affected (0.03 sec)mysql> select * from t2;
+----+------+
| id | tid |
+----+------+
| 1 | NULL |
| 2 | 1 |
+----+------+
2 rows in set (0.00 sec)mysql> select version();
+----------------------+
| version() |
+----------------------+
| 5.1.33-community-log |
+----------------------+
1 row in set (0.00 sec)mysql>
-> id int primary key,
-> tid int,
-> FOREIGN KEY (tid) REFERENCES t1(id)
-> )engine=innodb;
mysql innodb支持外键约束myisam不支持外键
show variables like 'foreign_key_checks' 看看支持不?