-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase structure
198 lines (160 loc) · 4.79 KB
/
Database structure
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
USE [_command_DB]
GO
/****** Object: Trigger [dbo].[ProductInsertTrigger] Script Date: 4-5-2024 19:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[ProductInsertTrigger]
ON [dbo].[Products]
AFTER INSERT
AS
BEGIN
INSERT INTO _query_client_DB.dbo.Products
(
[Name],
[Description],
[Price],
[Barcode],
[Company],
[OperatingSystem],
[Prosessor],
[Screen],
[Videocard]
)
VALUES
(
(SELECT [Name] FROM inserted),
(SELECT [Description] FROM inserted),
(SELECT [Price] FROM inserted),
(SELECT [Barcode] FROM inserted),
(SELECT [Company] FROM inserted),
(SELECT [OperatingSystem] FROM inserted),
(SELECT [Prosessor] FROM inserted),
(SELECT [Screen] FROM inserted),
(SELECT [Videocard] FROM inserted)
)
END;
GO
ALTER TABLE [dbo].[Products] ENABLE TRIGGER [ProductInsertTrigger]
GO
=================================================================================================================
USE [_command_DB]
GO
/****** Object: Trigger [dbo].[ProductRemoveTrigger] Script Date: 4-5-2024 19:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[ProductRemoveTrigger]
ON [dbo].[Products]
AFTER DELETE
AS
BEGIN
DELETE FROM _query_client_DB.dbo.Products
WHERE Barcode=(SELECT Barcode FROM deleted)
END
GO
ALTER TABLE [dbo].[Products] ENABLE TRIGGER [ProductRemoveTrigger]
GO
=================================================================================================
USE [_command_DB]
GO
/****** Object: Trigger [dbo].[ProductUpdateTrigger] Script Date: 4-5-2024 19:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[ProductUpdateTrigger]
ON [dbo].[Products]
AFTER UPDATE
AS
BEGIN
UPDATE _query_client_DB.dbo.Products
SET
Barcode = (SELECT Barcode FROM inserted),
Price = (SELECT Price FROM inserted)
WHERE
Barcode = (SELECT Barcode FROM deleted)
OR
Price = (SELECT Price FROM deleted);
END;
GO
ALTER TABLE [dbo].[Products] ENABLE TRIGGER [ProductUpdateTrigger]
GO
==============================================================================================================
USE [_command_DB]
GO
/****** Object: Trigger [dbo].[OrderInsertTrigger] Script Date: 4-5-2024 19:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[OrderInsertTrigger]
ON [dbo].[Orders]
AFTER INSERT
AS
BEGIN
INSERT INTO _query_company_DB.dbo.ClientOrderProducts
(
OrderCode,
OrderCreatedTime,
OrderDeedline,
CustomerPIN,
CustomerName,
CustomerSername,
ProductBarcode,
ProductName,
ProductDescription,
ProductVideocard,
ProductOperatingSystem,
ProductScreen,
ProductProsessor,
ProductCompany,
ProductCreatedTime,
ProductPrice
)
VALUES
(
(SELECT Code FROM inserted),
(SELECT CreatedTime FROM inserted),
(SELECT Deedline FROM inserted),
(SELECT CustomerPIN FROM inserted),
(SELECT [Name] FROM _command_DB.dbo.Customers WHERE Customers.ID=(SELECT CustomerID FROM inserted)),
(SELECT [Surname] FROM _command_DB.dbo.Customers WHERE Customers.ID=(SELECT CustomerID FROM inserted)),
(SELECT ProductBarcode FROM inserted),
(SELECT [Barcode] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Name] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Videocard] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [OperatingSystem] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Screen] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Prosessor] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Company] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [CreatedTime] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted)),
(SELECT [Price] FROM _command_DB.dbo.Products WHERE Products.ID= (SELECT ProductID FROM inserted))
)
END;
GO
ALTER TABLE [dbo].[Orders] ENABLE TRIGGER [OrderInsertTrigger]
GO
========================================================================================================================
USE [_command_DB]
GO
/****** Object: Trigger [dbo].[OrderUpdateTrigger] Script Date: 4-5-2024 19:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[OrderUpdateTrigger]
ON [dbo].[Orders]
AFTER UPDATE
AS
BEGIN
UPDATE _query_company_DB.dbo.ClientOrderProducts
SET
OrderCode=(SELECT Code FROM inserted)
WHERE ID=(SELECT ID From inserted)
END;
GO
ALTER TABLE [dbo].[Orders] ENABLE TRIGGER [OrderUpdateTrigger]
GO