-
Notifications
You must be signed in to change notification settings - Fork 9
/
db.sql
36 lines (31 loc) · 1.22 KB
/
db.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
DROP DATABASE IF EXISTS library;
CREATE DATABASE library;
USE library;
CREATE TABLE `tbl_book` (
`book_id` int(11) NOT NULL AUTO_INCREMENT,
`book_name` varchar(45) NOT NULL UNIQUE,
`book_author` varchar(45) NOT NULL,
PRIMARY KEY (`book_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_student` (
`student_id` int(11) NOT NULL AUTO_INCREMENT,
`student_name` varchar(45) NOT NULL UNIQUE,
`student_age` int(11) NOT NULL,
`street_address` varchar(45) DEFAULT NULL,
`street_address_2` varchar(45) DEFAULT NULL,
`city` varchar(45) DEFAULT NULL,
`state` varchar(45) DEFAULT NULL,
`zip_code` varchar(45) DEFAULT NULL,
`country` varchar(45) DEFAULT NULL,
PRIMARY KEY (`student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_student_book` (
`student_book_id` int(11) NOT NULL AUTO_INCREMENT,
`student_id` int(11) NOT NULL,
`book_id` int(11) NOT NULL,
KEY `fk_student` (`student_id`),
KEY `fk_book` (`book_id`),
PRIMARY KEY (`student_book_id`),
CONSTRAINT `fk_student` FOREIGN KEY (`student_id`) REFERENCES `tbl_student` (`student_id`) ON UPDATE CASCADE,
CONSTRAINT `fk_book` FOREIGN KEY (`book_id`) REFERENCES `tbl_book` (`book_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;