Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 DROP TABLE IF EXISTS domains; | 1 DROP TABLE IF EXISTS domains; |
2 DROP TABLE IF EXISTS corrections; | 2 DROP TABLE IF EXISTS corrections; |
3 | 3 |
4 CREATE TABLE domains( | 4 CREATE TABLE domains( |
5 id INT NOT NULL AUTO_INCREMENT, | 5 id INT NOT NULL AUTO_INCREMENT, |
6 domain VARCHAR(50) NOT NULL, | 6 domain VARCHAR(50) NOT NULL, |
7 domain_correct FLOAT(10,10), | 7 PRIMARY KEY(id), |
8 correction_correct FLOAT(10,10), | 8 UNIQUE(domain) |
Wladimir Palant
2012/10/09 11:51:14
Aren't these two fields just derivatives of the da
| |
9 PRIMARY KEY(id) | |
10 ); | 9 ); |
11 | 10 |
12 CREATE TABLE corrections( | 11 CREATE TABLE corrections( |
13 id INT NOT NULL AUTO_INCREMENT, | 12 id INT NOT NULL AUTO_INCREMENT, |
14 domain INT NOT NULL, | 13 domain INT NOT NULL, |
15 status INT NOT NULL, | 14 status INT NOT NULL, |
16 curr_month INT NOT NULL, | 15 curr_month INT NOT NULL, |
17 prev_month INT NOT NULL, | 16 prev_month INT NOT NULL, |
18 curr_year INT NOT NULL, | 17 curr_year INT NOT NULL, |
19 prev_year INT NOT NULL, | 18 prev_year INT NOT NULL, |
20 PRIMARY KEY(id), | 19 PRIMARY KEY(id), |
21 FOREIGN KEY(domain) REFERENCES domains(id) | 20 FOREIGN KEY(domain) REFERENCES domains(id), |
21 UNIQUE(domain, status) | |
22 ); | 22 ); |
23 | |
24 CREATE UNIQUE INDEX idx_domain ON domains(domain); | |
25 CREATE UNIQUE INDEX idx_domain_status ON corrections(domain, status); | |
Wladimir Palant
2012/10/09 11:51:14
Use UNIQUE constraint instead of these two indexes
Thomas Greiner
2012/10/09 13:47:02
I prefer having indexes because SELECTs on this ta
Wladimir Palant
2012/10/09 14:17:08
A UNIQUE constraint will always create an index im
| |
LEFT | RIGHT |