This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_dwh.sql
201 lines (199 loc) · 6.97 KB
/
db_dwh.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
USE [master]
GO
/****** Object: Database [TIAE6_DT_DWH] Script Date: 09.07.2021 12:14:17 ******/
CREATE DATABASE [TIAE6_DT_DWH];
GO
USE TIAE6_DT_DWH;
GO
CREATE TABLE [dbo].[DimContractSignDate](
[ContractSignDateId] [int] NOT NULL,
[Year] [int] NOT NULL,
[Month] [int] NOT NULL,
[Week] [int] NOT NULL,
[Day] [int] NOT NULL,
CONSTRAINT [PK_DimContractSignDate] PRIMARY KEY CLUSTERED
(
[ContractSignDateId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimContractValidFrom] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimContractValidFrom](
[ContractValidFromId] [int] NOT NULL,
[Year] [int] NOT NULL,
[Month] [int] NOT NULL,
[Week] [int] NOT NULL,
[Day] [int] NOT NULL,
CONSTRAINT [PK_DimContractValidFrom] PRIMARY KEY CLUSTERED
(
[ContractValidFromId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimContractValidTo] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimContractValidTo](
[ContractValidToId] [int] NOT NULL,
[Year] [int] NOT NULL,
[Month] [int] NOT NULL,
[Week] [int] NOT NULL,
[Day] [int] NOT NULL,
CONSTRAINT [PK_DimContractValidTo] PRIMARY KEY CLUSTERED
(
[ContractValidToId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimCustomer] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimCustomer](
[CustomerId] [int] NOT NULL,
[FirstName] [varchar](50) NOT NULL,
[LastName] [varchar](50) NOT NULL,
[Phone] [varchar](50) NOT NULL,
[BirthDate] [date] NOT NULL,
[Gender] [char](1) NOT NULL,
CONSTRAINT [PK_DimCustomer] PRIMARY KEY CLUSTERED
(
[CustomerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimDevice] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimDevice](
[DeviceId] [int] NOT NULL,
[DeviceName] [varchar](50) NOT NULL,
[DeviceBrand] [varchar](50) NOT NULL,
[DeviceType] [varchar](50) NOT NULL,
[DevicePrice] [money] NOT NULL,
[PurchasePrice] [money] NOT NULL,
[CompanyName] [varchar](50) NOT NULL,
[Phone] [varchar](50) NOT NULL,
[IsPrivateLabel] [bit] NOT NULL,
[DeviceWareHouseAmount] [int] NOT NULL,
[WareHouseName] [varchar](50) NOT NULL,
[WareHousePhone] [varchar](50) NOT NULL,
[WareHouseCapacity] [varchar](50) NOT NULL,
CONSTRAINT [PK_DimDevice] PRIMARY KEY CLUSTERED
(
[DeviceId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimLocation] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimLocation](
[LocationId] [int] NOT NULL,
[Street] [varchar](50) NOT NULL,
[City] [varchar](50) NOT NULL,
[Region] [varchar](50) NOT NULL,
[ZipCode] [varchar](50) NOT NULL,
[Country] [varchar](50) NOT NULL,
CONSTRAINT [PK_DimLocation] PRIMARY KEY CLUSTERED
(
[LocationId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[DimStore] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DimStore](
[StoreId] [int] NOT NULL,
[StoreName] [varchar](50) NOT NULL,
[StorePhone] [varchar](50) NOT NULL,
CONSTRAINT [PK_DimStore] PRIMARY KEY CLUSTERED
(
[StoreId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[FactSales] Script Date: 09.07.2021 12:14:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[FactSales](
[ContractId] [int] NOT NULL,
[CustomerId] [int] NOT NULL,
[DeviceId] [int] NOT NULL,
[StoreId] [int] NOT NULL,
[LocationId] [int] NOT NULL,
[ContractSignDateId] [int] NOT NULL,
[ContractValidFromId] [int] NOT NULL,
[ContractValidToId] [int] NOT NULL,
[ContractName] [varchar](50) NOT NULL,
[ContractType] [varchar](50) NOT NULL,
[ContractState] [char](10) NOT NULL,
[ContractPrice] [money] NOT NULL,
CONSTRAINT [PK_FactSales] PRIMARY KEY CLUSTERED
(
[ContractId] ASC,
[CustomerId] ASC,
[DeviceId] ASC,
[StoreId] ASC,
[LocationId] ASC,
[ContractSignDateId] ASC,
[ContractValidFromId] ASC,
[ContractValidToId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_ContractSignDateId] FOREIGN KEY([ContractSignDateId])
REFERENCES [dbo].[DimContractSignDate] ([ContractSignDateId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_ContractSignDateId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_ContractValidFromId] FOREIGN KEY([ContractValidFromId])
REFERENCES [dbo].[DimContractValidFrom] ([ContractValidFromId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_ContractValidFromId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_ContractValidToId] FOREIGN KEY([ContractValidToId])
REFERENCES [dbo].[DimContractValidTo] ([ContractValidToId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_ContractValidToId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_CustomerId] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[DimCustomer] ([CustomerId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_CustomerId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_DeviceId] FOREIGN KEY([DeviceId])
REFERENCES [dbo].[DimDevice] ([DeviceId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_DeviceId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_LocationId] FOREIGN KEY([LocationId])
REFERENCES [dbo].[DimLocation] ([LocationId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_LocationId]
GO
ALTER TABLE [dbo].[FactSales] WITH CHECK ADD CONSTRAINT [FK_StoreId] FOREIGN KEY([StoreId])
REFERENCES [dbo].[DimStore] ([StoreId])
GO
ALTER TABLE [dbo].[FactSales] CHECK CONSTRAINT [FK_StoreId]
GO
USE [master]
GO
ALTER DATABASE [TIAE6_DT_DWH] SET READ_WRITE
GO