alxkolm

chat schema

Sep 30th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.86 KB | None | 0 0
  1. CREATE TABLE `chat` (
  2.     `id` INT(11) NOT NULL AUTO_INCREMENT,
  3.     `name` VARCHAR(50) NOT NULL,
  4.     PRIMARY KEY (`id`),
  5.     UNIQUE INDEX `name` (`name`)
  6. )
  7. COLLATE='utf8_general_ci'
  8. ENGINE=InnoDB
  9. ;
  10.  
  11. CREATE TABLE `user` (
  12.     `id` INT(11) NOT NULL AUTO_INCREMENT,
  13.     `name` VARCHAR(50) NOT NULL,
  14.     PRIMARY KEY (`id`),
  15.     UNIQUE INDEX `name` (`name`)
  16. )
  17. COLLATE='utf8_general_ci'
  18. ENGINE=InnoDB
  19. ;
  20.  
  21. CREATE TABLE `message` (
  22.     `id` INT(11) NOT NULL AUTO_INCREMENT,
  23.     `chat_id` INT(11) NOT NULL,
  24.     `user_id` INT(11) NOT NULL,
  25.     `text` TEXT NOT NULL,
  26.     `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  27.     PRIMARY KEY (`id`),
  28.     INDEX `chat_id` (`chat_id`),
  29.     INDEX `user_id` (`user_id`),
  30.     CONSTRAINT `chat_id` FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`),
  31.     CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
  32. )
  33. COLLATE='utf8_general_ci'
  34. ENGINE=InnoDB
  35. ;
Advertisement
Add Comment
Please, Sign In to add comment