-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRezeed.sql
98 lines (85 loc) · 3.07 KB
/
Rezeed.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- MySQL Script generated by MySQL Workbench
-- Mon Nov 24 16:05:44 2014
-- Model: New Model Version: 1.0
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema rezeed
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `rezeed` ;
CREATE SCHEMA IF NOT EXISTS `rezeed` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `rezeed` ;
-- -----------------------------------------------------
-- Table `rezeed`.`User`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rezeed`.`User` (
`UserID` INT NOT NULL AUTO_INCREMENT,
`User` VARCHAR(45) NOT NULL,
`Password` BLOB NOT NULL,
PRIMARY KEY (`UserID`),
UNIQUE INDEX `User_UNIQUE` (`User` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `rezeed`.`PrivatePlaylist`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rezeed`.`PrivatePlaylist` (
`UserID` INT NOT NULL,
`SongID` INT NOT NULL,
INDEX `fk_User_has_Song_User_idx` (`UserID` ASC),
UNIQUE INDEX `UNIQUE` (`UserID` ASC, `SongID` ASC),
CONSTRAINT `fk_User_has_Song_User`
FOREIGN KEY (`UserID`)
REFERENCES `rezeed`.`User` (`UserID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `rezeed`.`PublicPlaylist`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rezeed`.`PublicPlaylist` (
`UserID` INT NOT NULL,
`SongID` INT NOT NULL,
`Likes` INT NOT NULL,
INDEX `fk_PublicPlaylist_User1_idx` (`UserID` ASC),
PRIMARY KEY (`SongID`),
CONSTRAINT `fk_PublicPlaylist_User1`
FOREIGN KEY (`UserID`)
REFERENCES `rezeed`.`User` (`UserID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `rezeed`.`Like`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rezeed`.`Like` (
`SongID` INT NOT NULL,
`UserID` INT NOT NULL,
INDEX `fk_PublicPlaylist_has_User_User1_idx` (`UserID` ASC),
INDEX `fk_PublicPlaylist_has_User_PublicPlaylist1_idx` (`SongID` ASC),
UNIQUE INDEX `UNIQUE` (`SongID` ASC, `UserID` ASC),
CONSTRAINT `fk_PublicPlaylist_has_User_PublicPlaylist1`
FOREIGN KEY (`SongID`)
REFERENCES `rezeed`.`PublicPlaylist` (`SongID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_PublicPlaylist_has_User_User1`
FOREIGN KEY (`UserID`)
REFERENCES `rezeed`.`User` (`UserID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
USE `rezeed`;
DELIMITER $$
USE `rezeed`$$
CREATE TRIGGER `Like_AINS` AFTER INSERT ON `Like` FOR EACH ROW
begin
update PublicPlaylist
set Likes = Likes+1
where SongID = new.SongID;
end;
delimiter ;$$
DELIMITER ;