-
Notifications
You must be signed in to change notification settings - Fork 0
/
opticianDB.sql
117 lines (104 loc) · 3.86 KB
/
opticianDB.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- -------------------------
-- Drop and create database
-- -------------------------
DROP DATABASE IF EXISTS `optician`;
CREATE DATABASE `optician` DEFAULT CHARACTER SET utf8;
USE `optician`;
-- ---------------------------
-- Create table `suppliers`
-- ---------------------------
CREATE TABLE IF NOT EXISTS `suppliers` (
`supplierId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`adress` VARCHAR(80) NULL,
`phone` VARCHAR(50)NULL,
`fax` VARCHAR(50),
`NIF` VARCHAR(9),
PRIMARY KEY(`supplierId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -------------------------
-- Create table `brands`
-- -------------------------
CREATE TABLE IF NOT EXISTS `brands` (
`brandId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`idSupplier` TINYINT(4),
PRIMARY KEY(`brandId`),
FOREIGN KEY (`idSupplier`)
REFERENCES `optician`.`suppliers` (`supplierId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -------------------------
-- Create table `glasses`
-- -------------------------
CREATE TABLE IF NOT EXISTS `glasses` (
`glassesId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`idBrand` TINYINT(4) NOT NULL,
`prescriptionL` ENUM("0.00", "+0.25", "-0.25", "+0.50", "-0.50", "+0.75", "-0.75", "+1.00", "-1.00", "+1.25", "-1.25", "+1.50", "-1.50", "+1.75", "-1.75", "+2.00", "-2.00", "+2.25", "-2.25", "+2.50", "-2.50", "+2.75", "-2.75", "+3.00", "-3.00") NOT NULL,
`prescriptionR` ENUM("0.00", "+0.25", "-0.25", "+0.50", "-0.50", "+0.75", "-0.75", "+1.00", "-1.00", "+1.25", "-1.25", "+1.50", "-1.50", "+1.75", "-1.75", "+2.00", "-2.00", "+2.25", "-2.25", "+2.50", "-2.50", "+2.75", "-2.75", "+3.00", "-3.00") NOT NULL,
`frame` ENUM("rimless", "resin", "metal") NOT NULL,
`frameColour` VARCHAR(50) NOT NULL,
`glassColourL` VARCHAR(50) NOT NULL,
`glassColourR` VARCHAR(50) NOT NULL,
`price` FLOAT NOT NULL,
PRIMARY KEY(`glassesId`),
FOREIGN KEY (`idBrand`)
REFERENCES `optician`.`brands` (`brandId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- ------------------------
-- Create table `customers`
-- ------------------------
CREATE TABLE IF NOT EXISTS `customers` (
`customerId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`adress` VARCHAR(50),
`phone` VARCHAR(50) NOT NULL,
`email` VARCHAR(80) NOT NULL,
`registerDate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`idRecomendedFor` TINYINT(4),
PRIMARY KEY(`customerId`),
FOREIGN KEY (`idRecomendedFor`)
REFERENCES `optician`.`customers` (`customerId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -------------------------
-- Create table `sellers`
-- -------------------------
CREATE TABLE IF NOT EXISTS `sellers` (
`sellerId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY(`sellerId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- ------------------------
-- Create table `purchases`
-- ------------------------
CREATE TABLE IF NOT EXISTS `purchases` (
`purchaseId` TINYINT(4) NOT NULL AUTO_INCREMENT,
`idCustomer` TINYINT(4) NOT NULL,
`idGlasses` TINYINT(4) NOT NULL,
`idSeller` TINYINT(4) NOT NULL,
`purchaseDate` DATE NOT NULL,
PRIMARY KEY(`purchaseId`),
FOREIGN KEY (`idCustomer`)
REFERENCES `optician`.`customers` (`customerId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY (`idGlasses`)
REFERENCES `optician`.`glasses` (`glassesId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY (`idSeller`)
REFERENCES `optician`.`sellers` (`sellerId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;