
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.34 KB | hits: 15 | expires: Never
MySQL REPLACE behaves differently than UPDATE if the PRIMARY KEY is referenced by a FOREIGN KEY
CREATE TABLE `category` (
`category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` mediumint(8) unsigned NOT NULL,
`name` varchar(20) CHARACTER SET ascii NOT NULL,
`description` varchar(100) DEFAULT NULL,
`repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT '0',
`color` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`category_id`),
KEY `id` (`user_id`),
CONSTRAINT `category_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `event` (
`event_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`category_id` int(10) unsigned NOT NULL,
`name` varchar(20) CHARACTER SET ascii NOT NULL,
`description` varchar(100) DEFAULT NULL,
`repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT '0',
`color` mediumint(8) unsigned NOT NULL,
`priority` tinyint(3) unsigned NOT NULL DEFAULT '0',
`start` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`end` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`done` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`event_id`),
KEY `category_id` (`category_id`),
CONSTRAINT `event_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;