irwan

FOREIGN KEY

Oct 1st, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. -- Database: `test`
  2. --
  3.  
  4. -- --------------------------------------------------------
  5.  
  6. --
  7. -- Table structure for table `table_1`
  8. --
  9.  
  10. CREATE TABLE IF NOT EXISTS `table_1` (
  11. `id` varchar(11) NOT NULL DEFAULT '',
  12. `name` varchar(20) DEFAULT NULL,
  13. `comment` varchar(20) DEFAULT NULL,
  14. PRIMARY KEY (`id`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  16.  
  17. -- --------------------------------------------------------
  18.  
  19. --
  20. -- Table structure for table `table_2`
  21. --
  22.  
  23. CREATE TABLE IF NOT EXISTS `table_2` (
  24. `address` varchar(20) NOT NULL DEFAULT '',
  25. `email` varchar(20) DEFAULT NULL,
  26. PRIMARY KEY (`address`)
  27. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  28.  
  29. -- --------------------------------------------------------
  30.  
  31. --
  32. -- Table structure for table `table_3`
  33. --
  34.  
  35. CREATE TABLE TABLE_3
  36. (
  37. id varchar(11),
  38. address varchar(20),
  39. email varchar(20),
  40. PRIMARY KEY (id, address),
  41. FOREIGN KEY (id) REFERENCES TABLE_1 (id) ON DELETE CASCADE ON UPDATE CASCADE,
  42. FOREIGN KEY (address) REFERENCES TABLE_2 (address) ON DELETE CASCADE ON UPDATE CASCADE
  43. )
  44.  
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment