-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhysicalModel-AzureSQL.sql
174 lines (139 loc) · 5.01 KB
/
PhysicalModel-AzureSQL.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* ER/Studio Data Architect SQL Code Generation
* Project : midterm_final-model.DM1
*
* Date Created : Sunday, October 22, 2023 21:58:39
* Target DBMS : Microsoft Azure SQL DB
*/
/*
* TABLE: BusinessDim
*/
CREATE TABLE BusinessDim(
BusinessKey_sk int NOT NULL,
BusinessId varchar(18) NOT NULL,
Name varchar(255) NULL,
Address varchar(255) NULL,
City varchar(255) NULL,
State varchar(255) NULL,
Zipcode varchar(18) NULL,
PhoneNumber varchar(20) NULL,
Latitude varchar(30) NULL,
Longitude varchar(20) NULL,
DI_CreatedDate date NULL,
DI_WorkflowFileName varchar(10) NULL,
DI_Workflow_ProcessID varchar(10) NULL,
CONSTRAINT PK2 PRIMARY KEY NONCLUSTERED (BusinessKey_sk)
)
go
IF OBJECT_ID('BusinessDim') IS NOT NULL
PRINT '<<< CREATED TABLE BusinessDim >>>'
ELSE
PRINT '<<< FAILED CREATING TABLE BusinessDim >>>'
go
/*
* TABLE: DateDim
*/
CREATE TABLE DateDim(
DateKey int NOT NULL,
CompleteDate date NULL,
Date int NOT NULL,
Year int NULL,
Quarter int NULL,
Month int NULL,
Week int NULL,
Day varchar(10) NULL,
Weekend_Weekday varchar(10) NULL,
DI_CreatedDate date NULL,
DI_WorkflowFileName varchar(255) NULL,
DI_Workflow_ProcessID varchar(10) NULL,
CONSTRAINT PK5 PRIMARY KEY NONCLUSTERED (DateKey)
)
go
IF OBJECT_ID('DateDim') IS NOT NULL
PRINT '<<< CREATED TABLE DateDim >>>'
ELSE
PRINT '<<< FAILED CREATING TABLE DateDim >>>'
go
/*
* TABLE: InspectionsFacts
*/
CREATE TABLE InspectionsFacts(
BusinessKey_sk int NOT NULL,
DateKey int NOT NULL,
InspectionFact_sk int NOT NULL,
InspectionId varchar(10) NULL,
InspectionType varchar(255) NULL,
ViolationTotalScore int NULL,
InspectionResult varchar(10) NULL,
DI_CreatedDate date NULL,
DI_WorkflowFileName char(255) NULL,
DI_Workflow_ProcessID varchar(10) NULL,
CONSTRAINT PK1 PRIMARY KEY NONCLUSTERED (InspectionFact_sk)
)
go
IF OBJECT_ID('InspectionsFacts') IS NOT NULL
PRINT '<<< CREATED TABLE InspectionsFacts >>>'
ELSE
PRINT '<<< FAILED CREATING TABLE InspectionsFacts >>>'
go
/*
* TABLE: InspectionViolationFact
*/
CREATE TABLE InspectionViolationFact(
InspectionViolationKey_sk int NOT NULL,
InspectionFact_sk int NOT NULL,
ViolationKey_sk int NOT NULL,
DI_CreatedDate date NULL,
DI_WorkfkowFileName char(255) NULL,
DI_Workflow_ProcessID varchar(10) NULL,
CONSTRAINT PK7 PRIMARY KEY NONCLUSTERED (InspectionViolationKey_sk)
)
go
IF OBJECT_ID('InspectionViolationFact') IS NOT NULL
PRINT '<<< CREATED TABLE InspectionViolationFact >>>'
ELSE
PRINT '<<< FAILED CREATING TABLE InspectionViolationFact >>>'
go
/*
* TABLE: ViolationDim
*/
CREATE TABLE ViolationDim(
ViolationKey_sk int NOT NULL,
ViolationId varchar(10) NOT NULL,
ViolationCode varchar(10) NULL,
ViolationDescription varchar(255) NULL,
ViolationCategory varchar(255) NULL,
ViolationScore int NULL,
DI_CreatedDate date NULL,
DI_WorkflowFileName varchar(255) NULL,
DI_Workflow_ProcessID varchar(10) NULL,
CONSTRAINT PK4 PRIMARY KEY NONCLUSTERED (ViolationKey_sk)
)
go
IF OBJECT_ID('ViolationDim') IS NOT NULL
PRINT '<<< CREATED TABLE ViolationDim >>>'
ELSE
PRINT '<<< FAILED CREATING TABLE ViolationDim >>>'
go
/*
* TABLE: InspectionsFacts
*/
ALTER TABLE InspectionsFacts ADD CONSTRAINT RefBusinessDim22
FOREIGN KEY (BusinessKey_sk)
REFERENCES BusinessDim(BusinessKey_sk)
go
ALTER TABLE InspectionsFacts ADD CONSTRAINT RefDateDim23
FOREIGN KEY (DateKey)
REFERENCES DateDim(DateKey)
go
/*
* TABLE: InspectionViolationFact
*/
ALTER TABLE InspectionViolationFact ADD CONSTRAINT RefInspectionsFacts47
FOREIGN KEY (InspectionFact_sk)
REFERENCES InspectionsFacts(InspectionFact_sk)
go
ALTER TABLE InspectionViolationFact ADD CONSTRAINT RefViolationDim49
FOREIGN KEY (ViolationKey_sk)
REFERENCES ViolationDim(ViolationKey_sk)
go