Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.34 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MySQL REPLACE behaves differently than UPDATE if the PRIMARY KEY is referenced by a FOREIGN KEY
  2. CREATE TABLE `category` (
  3.   `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  4.   `user_id` mediumint(8) unsigned NOT NULL,
  5.   `name` varchar(20) CHARACTER SET ascii NOT NULL,
  6.   `description` varchar(100) DEFAULT NULL,
  7.   `repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT '0',
  8.   `color` mediumint(8) unsigned NOT NULL,
  9.   PRIMARY KEY (`category_id`),
  10.   KEY `id` (`user_id`),
  11.   CONSTRAINT `category_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON  DELETE CASCADE
  12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  13.  
  14. CREATE TABLE `event` (
  15.   `event_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  16.   `category_id` int(10) unsigned NOT NULL,
  17.   `name` varchar(20) CHARACTER SET ascii NOT NULL,
  18.   `description` varchar(100) DEFAULT NULL,
  19.   `repeat_interval` tinyint(3) unsigned NOT NULL DEFAULT '0',
  20.   `color` mediumint(8) unsigned NOT NULL,
  21.   `priority` tinyint(3) unsigned NOT NULL DEFAULT '0',
  22.   `start` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  23.   `end` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  24.   `done` tinyint(1) NOT NULL DEFAULT '0',
  25.   PRIMARY KEY (`event_id`),
  26.   KEY `category_id` (`category_id`),
  27.   CONSTRAINT `event_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category`     (`category_id`) ON DELETE CASCADE
  28. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;