-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyii_catalog.sql
74 lines (58 loc) · 2.3 KB
/
yii_catalog.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
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
DROP TABLE IF EXISTS author;
CREATE TABLE IF NOT EXISTS author (
id int(11) NOT NULL,
first_name varchar(60) NOT NULL,
second_name varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
DROP TABLE IF EXISTS author2book;
CREATE TABLE IF NOT EXISTS author2book (
author_id int(11) NOT NULL,
book_id int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS book;
CREATE TABLE IF NOT EXISTS book (
id int(11) NOT NULL,
title varchar(120) NOT NULL,
cover varchar(120) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
DROP TABLE IF EXISTS subject;
CREATE TABLE IF NOT EXISTS `subject` (
id int(11) NOT NULL,
`name` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
DROP TABLE IF EXISTS subject2book;
CREATE TABLE IF NOT EXISTS subject2book (
subject_id int(11) NOT NULL,
book_id int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE author
ADD PRIMARY KEY (id);
ALTER TABLE author2book
ADD PRIMARY KEY (author_id,book_id), ADD KEY book_id (book_id);
ALTER TABLE book
ADD PRIMARY KEY (id);
ALTER TABLE subject
ADD PRIMARY KEY (id);
ALTER TABLE subject2book
ADD PRIMARY KEY (subject_id,book_id), ADD KEY book_id (book_id);
ALTER TABLE author
MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
ALTER TABLE book
MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;
ALTER TABLE subject
MODIFY id int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;
ALTER TABLE author2book
ADD CONSTRAINT author2book_ibfk_1 FOREIGN KEY (author_id) REFERENCES author (id),
ADD CONSTRAINT author2book_ibfk_2 FOREIGN KEY (book_id) REFERENCES book (id);
ALTER TABLE subject2book
ADD CONSTRAINT subject2book_ibfk_1 FOREIGN KEY (subject_id) REFERENCES subject (id),
ADD CONSTRAINT subject2book_ibfk_2 FOREIGN KEY (book_id) REFERENCES book (id);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;