-
Notifications
You must be signed in to change notification settings - Fork 0
/
likes.sql
33 lines (28 loc) · 1.04 KB
/
likes.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
CREATE TABLE `quietnet`.`likes` (
`lId` INT NOT NULL AUTO_INCREMENT,
`lPostid` INT NOT NULL,
`lUserid` INT NOT NULL,
PRIMARY KEY (`lId`),
INDEX `lPostid_idx` (`lPostid` ASC) VISIBLE,
INDEX `lUserid_idx` (`lUserid` ASC) VISIBLE,
CONSTRAINT `lPostid`
FOREIGN KEY (`lPostid`)
REFERENCES `quietnet`.`post` (`pId`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `lUserid`
FOREIGN KEY (`lUserid`)
REFERENCES `quietnet`.`user` (`uId`)
ON DELETE CASCADE
ON UPDATE CASCADE);
ALTER TABLE `likes`
ADD COLUMN `lDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER `lUserid`;
INSERT INTO `quietnet`.`likes` (`lPostid`, `lUserid`) VALUES ('21', '6');
INSERT INTO `quietnet`.`likes` (`lPostid`, `lUserid`) VALUES ('8', '9');
INSERT INTO `quietnet`.`likes` (`lPostid`, `lUserid`) VALUES ('10', '13');
INSERT INTO `quietnet`.`likes` (`lPostid`, `lUserid`) VALUES ('7', '1');
select count(*) from likes where lPostid=10;
desc likes;
select * from likes;
select count(*) from likes where lPostid=10;
-- delete from likes where lUserid!=0;