这是我制作的一张桌子:
mysql> show create table notes;
+-------+----------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------+
| notes | CREATE TABLE `notes` (
`id` int(11) NOT NULL auto_increment,
`note` text NOT NULL,
`status` enum('active','hidden','deleted','followup','starred') default NULL,
`created` datetime NOT NULL,
`last_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+----------------------------------------+
我尝试添加外键约束:
mysql> alter table notes add constraint foreign key(`id`) references `notetypes`.`id` on update cascade on delete restrict;
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0
没错!没有警告!由于这个原因,我一直在使用没有外键的内部数据库(假设它们存在)已经有一段时间了.不知道这是一个错误还是我做错了什么? mysql中可以避免这些陷阱的任何变通办法或选项吗?
$mysql --version
mysql Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (i486) using readline 5.2
谢谢
J.P