-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_init_script.txt
128 lines (112 loc) · 4.41 KB
/
db_init_script.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
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
118
119
120
121
122
123
124
125
126
127
128
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema supermarket
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema supermarket
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `supermarket` DEFAULT CHARACTER SET utf8 ;
USE `supermarket` ;
-- -----------------------------------------------------
-- Table `supermarket`.`city`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`city` (
`cityId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`zip` INT(10) UNSIGNED NOT NULL,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`cityId`))
ENGINE = InnoDB
AUTO_INCREMENT = 25
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `supermarket`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`user` (
`userName` VARCHAR(45) NOT NULL,
`firstName` VARCHAR(45) NULL DEFAULT NULL,
`lastName` VARCHAR(45) NULL DEFAULT NULL,
`email` VARCHAR(45) NOT NULL,
`cityId` INT(10) UNSIGNED NOT NULL,
`address` VARCHAR(100) NOT NULL,
`password` VARCHAR(45) NOT NULL,
`isAdmin` BIT(1) NOT NULL,
PRIMARY KEY (`userName`),
INDEX `cityId_idx` (`cityId` ASC),
CONSTRAINT `cityId`
FOREIGN KEY (`cityId`)
REFERENCES `supermarket`.`city` (`cityId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `supermarket`.`bill`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`bill` (
`billId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`userName` VARCHAR(45) NOT NULL,
PRIMARY KEY (`billId`),
INDEX `userName` (`userName` ASC),
CONSTRAINT `userName`
FOREIGN KEY (`userName`)
REFERENCES `supermarket`.`user` (`userName`))
ENGINE = InnoDB
AUTO_INCREMENT = 6
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `supermarket`.`category`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`category` (
`categoryId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`categoryId`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC))
ENGINE = InnoDB
AUTO_INCREMENT = 10
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `supermarket`.`product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`product` (
`productId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`price` INT(10) UNSIGNED NOT NULL,
`categoryId` INT(10) UNSIGNED NOT NULL,
`unit` VARCHAR(45) NOT NULL,
PRIMARY KEY (`productId`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC),
INDEX `category` (`categoryId` ASC),
CONSTRAINT `categoryId`
FOREIGN KEY (`categoryId`)
REFERENCES `supermarket`.`category` (`categoryId`))
ENGINE = InnoDB
AUTO_INCREMENT = 20
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `supermarket`.`billelement`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `supermarket`.`billelement` (
`billElementId` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`billId` INT(10) UNSIGNED NOT NULL,
`productId` INT(10) UNSIGNED NOT NULL,
`count` INT(10) UNSIGNED NOT NULL,
`price` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`billElementId`),
INDEX `billId` (`billId` ASC),
INDEX `productId` (`productId` ASC),
CONSTRAINT `billId`
FOREIGN KEY (`billId`)
REFERENCES `supermarket`.`bill` (`billId`),
CONSTRAINT `productId`
FOREIGN KEY (`productId`)
REFERENCES `supermarket`.`product` (`productId`))
ENGINE = InnoDB
AUTO_INCREMENT = 6
DEFAULT CHARACTER SET = utf8;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;