-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDatabase.sql
113 lines (97 loc) · 3.93 KB
/
createDatabase.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
-- -----------------------------------------------------
-- Schema easyMenu
-- -----------------------------------------------------
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'easyMenu')
BEGIN
CREATE DATABASE [easyMenu]
END
GO
USE [easyMenu]
GO
-- -----------------------------------------------------
-- Table `easyMenu`.`user`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='user' and xtype='U')
BEGIN
CREATE TABLE [user] (
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
userName varchar(50) NOT NULL,
email varchar(100) NOT NULL,
password varchar(50) NOT NULL,
createdDate DateTime NOT NULL DEFAULT GETDATE(),
updatedDate Datetime NULL,
)
END
-- -----------------------------------------------------
-- Table `easyMenu`.`menu`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='menu' and xtype='U')
BEGIN
CREATE TABLE menu (
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
title varchar(50) NOT NULL,
description varchar(200) NULL,
createdDate DateTime NOT NULL DEFAULT GETDATE(),
updatedDate Datetime NULL,
)
END
-- ---------------------------------------------------
-- Table `easyMenu`.`disheType`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='disheType' and xtype='U')
BEGIN
CREATE TABLE disheType (
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
title varchar(50) NOT NULL,
description varchar(200) NULL,
createdDate DateTime NOT NULL DEFAULT GETDATE(),
updatedDate Datetime NULL,
)
END
-- -----------------------------------------------------
-- Table `easyMenu`.`dishes`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='dishes' and xtype='U')
BEGIN
CREATE TABLE dishes(
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
title varchar(50) NOT NULL,
description varchar(200) NULL,
price decimal(10,2) NOT NULL DEFAULT 0,
portion int NOT NULL DEFAULT 1,
promotion int NULL DEFAULT 1,
promotionPrice decimal(10,2) NULL DEFAULT 0,
disheTypeId UNIQUEIDENTIFIER NOT NULL,
createdDate DateTime NOT NULL DEFAULT GETDATE(),
updatedDate Datetime NULL,
CONSTRAINT fk_disheTypeId FOREIGN KEY (disheTypeId) REFERENCES disheType (id)
)
END
-- ---------------------------------------------------
-- Table `easyMenu`.`menuOption`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='menuOption' and xtype='U')
BEGIN
CREATE TABLE menuOption(
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
menuId UNIQUEIDENTIFIER NOT NULL,
disheId UNIQUEIDENTIFIER NOT NULL,
CONSTRAINT fk_menuId FOREIGN KEY (menuId) REFERENCES menu (id),
CONSTRAINT fk_disheId FOREIGN KEY (disheId) REFERENCES dishes (id)
)
END
-- ---------------------------------------------------
-- Table `easyMenu`.`restaurant`
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='restaurant' and xtype='U')
BEGIN
CREATE TABLE restaurant(
id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
name varchar(50) NOT NULL,
address varchar(200) NULL,
menuId UNIQUEIDENTIFIER NOT NULL,
createdDate DateTime NOT NULL DEFAULT GETDATE(),
updatedDate Datetime NULL,
CONSTRAINT fk_menuId_restaurant FOREIGN KEY (menuId) REFERENCES menu (id),
)
END