-
Notifications
You must be signed in to change notification settings - Fork 152
/
DBCreationScript.txt
162 lines (155 loc) · 5.54 KB
/
DBCreationScript.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
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
USE [master]
GO
CREATE DATABASE [DddInPractice]
GO
USE [DddInPractice]
GO
/****** Object: Table [dbo].[Atm] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Atm](
[AtmID] [bigint] NOT NULL,
[MoneyCharged] [decimal](18, 2) NOT NULL,
[OneCentCount] [int] NOT NULL,
[TenCentCount] [int] NOT NULL,
[QuarterCount] [int] NOT NULL,
[OneDollarCount] [int] NOT NULL,
[FiveDollarCount] [int] NOT NULL,
[TwentyDollarCount] [int] NOT NULL,
CONSTRAINT [PK_Atm] PRIMARY KEY CLUSTERED
(
[AtmID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[HeadOffice] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[HeadOffice](
[HeadOfficeID] [bigint] NOT NULL,
[Balance] [decimal](18, 2) NOT NULL,
[OneCentCount] [int] NOT NULL,
[TenCentCount] [int] NOT NULL,
[QuarterCount] [int] NOT NULL,
[OneDollarCount] [int] NOT NULL,
[FiveDollarCount] [int] NOT NULL,
[TwentyDollarCount] [int] NOT NULL,
CONSTRAINT [PK_HeadOffice] PRIMARY KEY CLUSTERED
(
[HeadOfficeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Ids] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Ids](
[EntityName] [nvarchar](100) NOT NULL,
[NextHigh] [int] NOT NULL,
CONSTRAINT [PK_Ids] PRIMARY KEY CLUSTERED
(
[EntityName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Slot] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Slot](
[SlotID] [bigint] NOT NULL,
[Quantity] [int] NOT NULL,
[Price] [decimal](18, 2) NOT NULL,
[SnackID] [bigint] NOT NULL,
[SnackMachineID] [bigint] NOT NULL,
[Position] [int] NOT NULL,
CONSTRAINT [PK_Slot] PRIMARY KEY CLUSTERED
(
[SlotID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Snack] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Snack](
[SnackID] [bigint] NOT NULL,
[Name] [nvarchar](200) NOT NULL,
CONSTRAINT [PK_Snack] PRIMARY KEY CLUSTERED
(
[SnackID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[SnackMachine] Script Date: 1/5/2016 9:48:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SnackMachine](
[SnackMachineID] [bigint] NOT NULL,
[OneCentCount] [int] NOT NULL,
[TenCentCount] [int] NOT NULL,
[QuarterCount] [int] NOT NULL,
[OneDollarCount] [int] NOT NULL,
[FiveDollarCount] [int] NOT NULL,
[TwentyDollarCount] [int] NOT NULL,
CONSTRAINT [PK_SnackMachine] PRIMARY KEY CLUSTERED
(
[SnackMachineID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[Atm] ([AtmID], [MoneyCharged], [OneCentCount], [TenCentCount], [QuarterCount], [OneDollarCount], [FiveDollarCount], [TwentyDollarCount]) VALUES (1, CAST(0 AS Decimal(18, 2)), 20, 20, 20, 20,20, 20)
GO
INSERT [dbo].[HeadOffice] ([HeadOfficeID], [Balance], [OneCentCount], [TenCentCount], [QuarterCount], [OneDollarCount], [FiveDollarCount], [TwentyDollarCount]) VALUES (1, CAST(0 AS Decimal(18, 2)), 0, 0, 0, 0, 0, 0)
GO
INSERT [dbo].[Ids] ([EntityName], [NextHigh]) VALUES (N'Atm', 1)
GO
INSERT [dbo].[Ids] ([EntityName], [NextHigh]) VALUES (N'HeadOffice', 1)
GO
INSERT [dbo].[Ids] ([EntityName], [NextHigh]) VALUES (N'Slot', 1)
GO
INSERT [dbo].[Ids] ([EntityName], [NextHigh]) VALUES (N'Snack', 1)
GO
INSERT [dbo].[Ids] ([EntityName], [NextHigh]) VALUES (N'SnackMachine', 1)
GO
INSERT [dbo].[Slot] ([SlotID], [Quantity], [Price], [SnackID], [SnackMachineID], [Position]) VALUES (1, 10, CAST(3.00 AS Decimal(18, 2)), 1, 1, 1)
GO
INSERT [dbo].[Slot] ([SlotID], [Quantity], [Price], [SnackID], [SnackMachineID], [Position]) VALUES (2, 15, CAST(2.00 AS Decimal(18, 2)), 2, 1, 2)
GO
INSERT [dbo].[Slot] ([SlotID], [Quantity], [Price], [SnackID], [SnackMachineID], [Position]) VALUES (3, 20, CAST(1.00 AS Decimal(18, 2)), 3, 1, 3)
GO
INSERT [dbo].[Snack] ([SnackID], [Name]) VALUES (1, N'Chocolate')
GO
INSERT [dbo].[Snack] ([SnackID], [Name]) VALUES (2, N'Soda')
GO
INSERT [dbo].[Snack] ([SnackID], [Name]) VALUES (3, N'Gum')
GO
INSERT [dbo].[SnackMachine] ([SnackMachineID], [OneCentCount], [TenCentCount], [QuarterCount], [OneDollarCount], [FiveDollarCount], [TwentyDollarCount]) VALUES (1, 10, 10, 10, 10, 10, 10)
GO
ALTER TABLE [dbo].[Slot] ADD CONSTRAINT [DF_Slot_Position] DEFAULT ((1)) FOR [Position]
GO
ALTER TABLE [dbo].[Slot] WITH CHECK ADD CONSTRAINT [FK_Slot_Snack] FOREIGN KEY([SnackID])
REFERENCES [dbo].[Snack] ([SnackID])
GO
ALTER TABLE [dbo].[Slot] CHECK CONSTRAINT [FK_Slot_Snack]
GO
ALTER TABLE [dbo].[Slot] WITH CHECK ADD CONSTRAINT [FK_Slot_SnackMachine] FOREIGN KEY([SnackMachineID])
REFERENCES [dbo].[SnackMachine] ([SnackMachineID])
GO
ALTER TABLE [dbo].[Slot] CHECK CONSTRAINT [FK_Slot_SnackMachine]
GO
USE [master]
GO
ALTER DATABASE [DddInPractice] SET READ_WRITE
GO