-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL COMMANDS.txt
38 lines (31 loc) · 1.29 KB
/
SQL COMMANDS.txt
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
//to create the database
CREATE DATABASE restful_db;
//to use the Database
USE restful_db;
//To create the authors table
CREATE TABLE AUTHORS( AUTH_NAME VARCHAR(200),AUTH_ID INT PRIMARY KEY AUTO_INCREMENT)ENGINE=INNODB;
//To add random values to the authors table
INSERT INTO AUTHORS (AUTH_NAME) VALUES ('HARRY'),('RAVI'),('RAJ'),('ANITA GOEL'),('ARUTHUR HAILEY');
//to create books table
CREATE TABLE books (
book_name VARCHAR(200),
book_id INT PRIMARY KEY AUTO_INCREMENT,
auth_id INT,
FOREIGN KEY (auth_id)
REFERENCES AUTHORS(AUTH_ID)
ON DELETE CASCADE
) ENGINE=INNODB;
//To add random values to the books table
INSERT INTO AUTHORS (book_name,auth_id) VALUES ('book one',1),('book two',2),('book 3 ',3),('book 4',4),('book 5',5),('book 6',2),('book 7',4);
//to create reviews table
CREATE TABLE reviews (
content VARCHAR(2000),
review_id INT PRIMARY KEY AUTO_INCREMENT,
reviewer_name VARCHAR(200),
book_id INT,
FOREIGN KEY (book_id)
REFERENCES books(book_id)
ON DELETE CASCADE
) ENGINE=INNODB;
//To add random values to the reviews table
INSERT INTO AUTHORS (reviewer_name,review,book_id) VALUES ('bob','good review',1),('hari','average review,1),('manoj','average review,'3),('shankar','bad review',4),('midun','good review',5),('nithin','average review',5);