-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseScript.sql
774 lines (766 loc) · 52.8 KB
/
DatabaseScript.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
USE [master]
GO
/****** Object: Database [SupermarketDB] Script Date: 5/26/2024 2:00:52 PM ******/
CREATE DATABASE [SupermarketDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Supermarket', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\Supermarket.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'Supermarket_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\Supermarket_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF
GO
ALTER DATABASE [SupermarketDB] SET COMPATIBILITY_LEVEL = 160
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [SupermarketDB].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [SupermarketDB] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [SupermarketDB] SET ANSI_NULLS OFF
GO
ALTER DATABASE [SupermarketDB] SET ANSI_PADDING OFF
GO
ALTER DATABASE [SupermarketDB] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [SupermarketDB] SET ARITHABORT OFF
GO
ALTER DATABASE [SupermarketDB] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [SupermarketDB] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [SupermarketDB] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [SupermarketDB] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [SupermarketDB] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [SupermarketDB] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [SupermarketDB] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [SupermarketDB] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [SupermarketDB] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [SupermarketDB] SET DISABLE_BROKER
GO
ALTER DATABASE [SupermarketDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [SupermarketDB] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [SupermarketDB] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [SupermarketDB] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [SupermarketDB] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [SupermarketDB] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [SupermarketDB] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [SupermarketDB] SET RECOVERY FULL
GO
ALTER DATABASE [SupermarketDB] SET MULTI_USER
GO
ALTER DATABASE [SupermarketDB] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [SupermarketDB] SET DB_CHAINING OFF
GO
ALTER DATABASE [SupermarketDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [SupermarketDB] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
ALTER DATABASE [SupermarketDB] SET DELAYED_DURABILITY = DISABLED
GO
ALTER DATABASE [SupermarketDB] SET ACCELERATED_DATABASE_RECOVERY = OFF
GO
EXEC sys.sp_db_vardecimal_storage_format N'SupermarketDB', N'ON'
GO
ALTER DATABASE [SupermarketDB] SET QUERY_STORE = ON
GO
ALTER DATABASE [SupermarketDB] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 30), DATA_FLUSH_INTERVAL_SECONDS = 900, INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 1000, QUERY_CAPTURE_MODE = AUTO, SIZE_BASED_CLEANUP_MODE = AUTO, MAX_PLANS_PER_QUERY = 200, WAIT_STATS_CAPTURE_MODE = ON)
GO
USE [SupermarketDB]
GO
USE [SupermarketDB]
GO
/****** Object: Sequence [dbo].[ProductStocksSeq] Script Date: 5/26/2024 2:00:52 PM ******/
CREATE SEQUENCE [dbo].[ProductStocksSeq]
AS [bigint]
START WITH 1
INCREMENT BY 1
MINVALUE -9223372036854775808
MAXVALUE 9223372036854775807
CACHE
GO
USE [SupermarketDB]
GO
/****** Object: Sequence [dbo].[ReceiptIDSequence] Script Date: 5/26/2024 2:00:52 PM ******/
CREATE SEQUENCE [dbo].[ReceiptIDSequence]
AS [bigint]
START WITH 1
INCREMENT BY 1
MINVALUE -9223372036854775808
MAXVALUE 9223372036854775807
CACHE
GO
/****** Object: Table [dbo].[Category] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Category](
[id] [int] NOT NULL,
[name] [varchar](50) NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED
(
[id] 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].[Producer] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Producer](
[ID] [int] NOT NULL,
[Name] [varchar](50) NOT NULL,
[Country] [varchar](50) NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_Producer] PRIMARY KEY CLUSTERED
(
[ID] 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].[Product] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Product](
[BarCode] [varchar](50) NOT NULL,
[Name] [varchar](50) NOT NULL,
[CategoryID] [int] NOT NULL,
[ProducerID] [int] NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED
(
[BarCode] 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].[ProductOnReceipt] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProductOnReceipt](
[ReceiptID] [int] NOT NULL,
[BarCode] [varchar](50) NOT NULL,
[Quantity] [int] NOT NULL,
[Subtotal] [decimal](10, 2) NOT NULL,
[deleted] [bit] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[ProductStocks] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProductStocks](
[ID] [int] NOT NULL,
[BarCode] [varchar](50) NOT NULL,
[Quantity] [int] NOT NULL,
[Unit] [varchar](50) NOT NULL,
[SupplyDate] [date] NOT NULL,
[ExpiryDate] [date] NOT NULL,
[PurchasePrice] [decimal](10, 2) NOT NULL,
[SellingPrice] [decimal](10, 2) NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_ProductStocks] PRIMARY KEY CLUSTERED
(
[ID] 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].[Receipt] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Receipt](
[ID] [int] NOT NULL,
[ReleaseDate] [date] NOT NULL,
[CasherID] [int] NOT NULL,
[Total] [decimal](10, 2) NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_Receipt] PRIMARY KEY CLUSTERED
(
[ID] 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].[Users] Script Date: 5/26/2024 2:00:52 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
[ID] [int] NOT NULL,
[password] [varchar](50) NOT NULL,
[role] [varchar](50) NOT NULL,
[username] [varchar](50) NOT NULL,
[name] [varchar](50) NOT NULL,
[deleted] [bit] NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[ID] 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
INSERT [dbo].[Category] ([id], [name], [deleted]) VALUES (1, N'drink', 0)
INSERT [dbo].[Category] ([id], [name], [deleted]) VALUES (2, N'foods', 1)
INSERT [dbo].[Category] ([id], [name], [deleted]) VALUES (3, N'consumables', 0)
INSERT [dbo].[Category] ([id], [name], [deleted]) VALUES (4, N'vegetables', 1)
GO
INSERT [dbo].[Producer] ([ID], [Name], [Country], [deleted]) VALUES (1, N'Cocacola', N'Abudabi', 0)
INSERT [dbo].[Producer] ([ID], [Name], [Country], [deleted]) VALUES (2, N'pepsi', N'America', 0)
INSERT [dbo].[Producer] ([ID], [Name], [Country], [deleted]) VALUES (3, N'Fanta', N'England', 1)
INSERT [dbo].[Producer] ([ID], [Name], [Country], [deleted]) VALUES (4, N'Jveps', N'Romania', 1)
INSERT [dbo].[Producer] ([ID], [Name], [Country], [deleted]) VALUES (5, N'Fantastix', N'England', 0)
GO
INSERT [dbo].[Product] ([BarCode], [Name], [CategoryID], [ProducerID], [deleted]) VALUES (N'123', N'cola', 1, 1, 0)
INSERT [dbo].[Product] ([BarCode], [Name], [CategoryID], [ProducerID], [deleted]) VALUES (N'124', N'dasa', 1, 2, 0)
INSERT [dbo].[Product] ([BarCode], [Name], [CategoryID], [ProducerID], [deleted]) VALUES (N'125', N'Fanta', 1, 3, 0)
INSERT [dbo].[Product] ([BarCode], [Name], [CategoryID], [ProducerID], [deleted]) VALUES (N'128', N'Schweppes', 1, 1, 0)
GO
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (5, N'123', 4, CAST(32.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (5, N'124', 3, CAST(30.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (6, N'123', 2, CAST(16.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (6, N'124', 3, CAST(30.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (9, N'123', 10, CAST(80.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (10, N'124', 17, CAST(170.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (10, N'123', 1, CAST(8.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (7, N'124', 3, CAST(30.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (7, N'123', 6, CAST(48.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductOnReceipt] ([ReceiptID], [BarCode], [Quantity], [Subtotal], [deleted]) VALUES (8, N'123', 3, CAST(24.00 AS Decimal(10, 2)), 0)
GO
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (2, N'123', 15, N'Litres', CAST(N'2024-10-10' AS Date), CAST(N'2024-12-12' AS Date), CAST(5.00 AS Decimal(10, 2)), CAST(10.00 AS Decimal(10, 2)), 1)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (3, N'124', 28, N'Litres', CAST(N'2024-05-24' AS Date), CAST(N'2024-05-31' AS Date), CAST(7.00 AS Decimal(10, 2)), CAST(15.00 AS Decimal(10, 2)), 1)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (4, N'125', 0, N'Litres', CAST(N'2022-02-07' AS Date), CAST(N'2023-01-01' AS Date), CAST(4.00 AS Decimal(10, 2)), CAST(7.50 AS Decimal(10, 2)), 1)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (6, N'123', 50, N'Litres', CAST(N'2024-05-24' AS Date), CAST(N'2024-05-31' AS Date), CAST(5.00 AS Decimal(10, 2)), CAST(15.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (7, N'124', 28, N'Litres', CAST(N'2024-05-24' AS Date), CAST(N'2024-05-31' AS Date), CAST(7.00 AS Decimal(10, 2)), CAST(15.00 AS Decimal(10, 2)), 1)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (8, N'123', 0, N'Litres', CAST(N'2024-05-24' AS Date), CAST(N'2024-05-31' AS Date), CAST(5.00 AS Decimal(10, 2)), CAST(15.00 AS Decimal(10, 2)), 1)
INSERT [dbo].[ProductStocks] ([ID], [BarCode], [Quantity], [Unit], [SupplyDate], [ExpiryDate], [PurchasePrice], [SellingPrice], [deleted]) VALUES (9, N'124', 28, N'Litres', CAST(N'2024-05-24' AS Date), CAST(N'2024-05-31' AS Date), CAST(7.00 AS Decimal(10, 2)), CAST(105.00 AS Decimal(10, 2)), 1)
GO
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (5, CAST(N'2024-05-23' AS Date), 2, CAST(62.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (6, CAST(N'2024-05-23' AS Date), 2, CAST(46.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (7, CAST(N'2024-05-23' AS Date), 2, CAST(78.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (8, CAST(N'2024-05-23' AS Date), 2, CAST(24.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (9, CAST(N'2024-05-23' AS Date), 2, CAST(80.00 AS Decimal(10, 2)), 0)
INSERT [dbo].[Receipt] ([ID], [ReleaseDate], [CasherID], [Total], [deleted]) VALUES (10, CAST(N'2024-05-24' AS Date), 2, CAST(178.00 AS Decimal(10, 2)), 0)
GO
INSERT [dbo].[Users] ([ID], [password], [role], [username], [name], [deleted]) VALUES (1, N'admin', N'Administrator', N'admin', N'adminv1', 0)
INSERT [dbo].[Users] ([ID], [password], [role], [username], [name], [deleted]) VALUES (2, N'asd', N'Casier', N'asd', N'asd1', 0)
INSERT [dbo].[Users] ([ID], [password], [role], [username], [name], [deleted]) VALUES (3, N'asd', N'Casier', N'asd', N'PopaGeorge', 1)
GO
ALTER TABLE [dbo].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_Category] FOREIGN KEY([CategoryID])
REFERENCES [dbo].[Category] ([id])
GO
ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_Category]
GO
ALTER TABLE [dbo].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_Producer] FOREIGN KEY([ProducerID])
REFERENCES [dbo].[Producer] ([ID])
GO
ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_Producer]
GO
ALTER TABLE [dbo].[ProductOnReceipt] WITH CHECK ADD CONSTRAINT [Product_ReceiptProduct] FOREIGN KEY([BarCode])
REFERENCES [dbo].[Product] ([BarCode])
GO
ALTER TABLE [dbo].[ProductOnReceipt] CHECK CONSTRAINT [Product_ReceiptProduct]
GO
ALTER TABLE [dbo].[ProductOnReceipt] WITH CHECK ADD CONSTRAINT [Receipt_ProductOnReceipt] FOREIGN KEY([ReceiptID])
REFERENCES [dbo].[Receipt] ([ID])
GO
ALTER TABLE [dbo].[ProductOnReceipt] CHECK CONSTRAINT [Receipt_ProductOnReceipt]
GO
ALTER TABLE [dbo].[ProductStocks] WITH CHECK ADD CONSTRAINT [FK_ProductStocks_Product] FOREIGN KEY([BarCode])
REFERENCES [dbo].[Product] ([BarCode])
GO
ALTER TABLE [dbo].[ProductStocks] CHECK CONSTRAINT [FK_ProductStocks_Product]
GO
ALTER TABLE [dbo].[Receipt] WITH CHECK ADD CONSTRAINT [FK_Receipt_Users] FOREIGN KEY([CasherID])
REFERENCES [dbo].[Users] ([ID])
GO
ALTER TABLE [dbo].[Receipt] CHECK CONSTRAINT [FK_Receipt_Users]
GO
/****** Object: StoredProcedure [dbo].[AddCategory] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[AddCategory]
@ID INT,
@Name NVARCHAR(100),
@Deleted BIT
AS
BEGIN
INSERT INTO Category (ID, Name, deleted)
VALUES (@ID, @Name, @Deleted);
END;
GO
/****** Object: StoredProcedure [dbo].[AddProducer] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddProducer]
@ID INT,
@Name NVARCHAR(100),
@Country NVARCHAR(100),
@Deleted BIT
AS
BEGIN
INSERT INTO Producer (ID, Name, Country, deleted)
VALUES (@ID, @Name, @Country, @Deleted);
END;
GO
/****** Object: StoredProcedure [dbo].[AddProduct] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddProduct]
@Barcode NVARCHAR(50),
@Name NVARCHAR(100),
@CategoryID INT,
@ProducerID INT,
@Deleted BIT
AS
BEGIN
INSERT INTO Product (Barcode, Name, CategoryID, ProducerID, Deleted)
VALUES (@Barcode, @Name, @CategoryID, @ProducerID, @Deleted)
END
GO
/****** Object: StoredProcedure [dbo].[AddProductsOnReceipt] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddProductsOnReceipt]
@Barcode VARCHAR(50),
@Quantity INT,
@Subtotal DECIMAL(18, 2),
@Deleted BIT
AS
BEGIN
DECLARE @ReceiptID INT;
-- Obținem ultimul ReceiptID
SELECT @ReceiptID = MAX(ID) FROM Receipt;
-- Inserăm în tabela ProductOnReceipt
INSERT INTO ProductOnReceipt (ReceiptID, Barcode, Quantity, Subtotal, Deleted)
VALUES (@ReceiptID, @Barcode, @Quantity, @Subtotal, @Deleted);
END
GO
/****** Object: StoredProcedure [dbo].[AddReceipt] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddReceipt]
@ReleaseDate DATETIME,
@CasherID INT,
@Total DECIMAL(10, 2),
@Deleted BIT
AS
BEGIN
DECLARE @NewReceiptID INT;
SET @NewReceiptID = NEXT VALUE FOR ReceiptIDSequence;
INSERT INTO Receipt (ID, ReleaseDate, CasherID, Total, Deleted)
VALUES (@NewReceiptID, @ReleaseDate, @CasherID, @Total, @Deleted);
SELECT @NewReceiptID AS NewReceiptID;
END
GO
/****** Object: StoredProcedure [dbo].[AddStock] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddStock]
@Barcode NVARCHAR(50),
@Quantity INT,
@Unit NVARCHAR(50),
@SupplyDate DATETIME,
@ExpiryDate DATETIME,
@PurchasePrice DECIMAL(18, 2),
@SellingPrice DECIMAL(18, 2)
AS
BEGIN
DECLARE @Deleted BIT
SET @Deleted = CASE WHEN @Quantity = 0 THEN 1 ELSE 0 END
INSERT INTO ProductStocks (Barcode, Quantity, Unit, SupplyDate, ExpiryDate, PurchasePrice, SellingPrice, Deleted)
VALUES (@Barcode, @Quantity, @Unit, @SupplyDate, @ExpiryDate, @PurchasePrice, @SellingPrice, @Deleted)
END
GO
/****** Object: StoredProcedure [dbo].[AddUser] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddUser]
@ID INT,
@Name NVARCHAR(50),
@Password NVARCHAR(50),
@Username NVARCHAR(50),
@Role NVARCHAR(50),
@Deleted BIT
AS
BEGIN
IF NOT EXISTS (SELECT 1 FROM users WHERE Username = @Username)
BEGIN
INSERT INTO users (id, Name, Password, Username, Role, Deleted)
VALUES (@ID, @Name, @Password, @Username, @Role, @Deleted);
END
ELSE
BEGIN
RAISERROR('A user with the same username already exists.', 16, 1);
END
END;
GO
/****** Object: StoredProcedure [dbo].[DeleteCategory] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteCategory]
@ID INT
AS
BEGIN
UPDATE Category
SET deleted = 1
WHERE ID = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[DeleteProducer] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteProducer]
@ID INT
AS
BEGIN
UPDATE Producer
SET deleted = 1
WHERE ID = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[DeleteProduct] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteProduct]
@Barcode NVARCHAR(50)
AS
BEGIN
-- Setăm Deleted la true pentru produsul cu codul de bare specificat
UPDATE Product
SET Deleted = 1
WHERE Barcode = @Barcode;
END
GO
/****** Object: StoredProcedure [dbo].[DeleteStock] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteStock]
@Barcode NVARCHAR(100),
@Deleted BIT
AS
BEGIN
UPDATE ProductStocks
SET deleted = @Deleted
WHERE Barcode = @Barcode;
END
GO
/****** Object: StoredProcedure [dbo].[DeleteUser] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteUser]
@ID INT
AS
BEGIN
-- Actualizează coloana `deleted` pentru rândul specificat de `ID`
UPDATE users
SET deleted = 1
WHERE ID = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[EditCategory] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EditCategory]
@ID INT,
@Name NVARCHAR(100)
AS
BEGIN
UPDATE Category
SET Name = @Name
WHERE ID = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[EditProducer] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EditProducer]
@ID INT,
@Name NVARCHAR(100),
@Country NVARCHAR(100)
AS
BEGIN
UPDATE Producer
SET Name = @Name,
Country = @Country
WHERE ID = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[EditProduct] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EditProduct]
@Barcode NVARCHAR(50),
@Name NVARCHAR(100),
@CategoryID INT,
@ProducerID INT
AS
BEGIN
SET NOCOUNT ON;
UPDATE Product
SET Name = @Name,
CategoryID = @CategoryID,
ProducerID = @ProducerID
WHERE Barcode = @Barcode;
END
GO
/****** Object: StoredProcedure [dbo].[EditStock] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EditStock]
@ID INT,
@Barcode NVARCHAR(50),
@PurchasePrice DECIMAL(18, 2),
@Unit NVARCHAR(50),
@Quantity INT,
@SellingPrice DECIMAL(18, 2),
@DateOfSupply DATE,
@ExpirationDate DATE
AS
BEGIN
UPDATE ProductStocks
SET
PurchasePrice = @PurchasePrice,
Unit = @Unit,
Quantity = @Quantity,
SellingPrice = @SellingPrice,
SupplyDate = @DateOfSupply,
ExpiryDate = @ExpirationDate
WHERE ID = @ID
END
GO
/****** Object: StoredProcedure [dbo].[EditUser] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EditUser]
@ID INT,
@Name NVARCHAR(50),
@Password NVARCHAR(50),
@Username NVARCHAR(50),
@Role NVARCHAR(50)
AS
BEGIN
UPDATE users
SET
Name = @Name,
Password = @Password,
Username = @Username,
Role = @Role
WHERE Id = @ID;
END;
GO
/****** Object: StoredProcedure [dbo].[GetAllAccounts] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetAllAccounts]
AS
BEGIN
SET NOCOUNT ON;
SELECT Username, [Password],[Role],ID,name,deleted
FROM Users;
END
GO
/****** Object: StoredProcedure [dbo].[GetCategoryDetails] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetCategoryDetails]
AS
BEGIN
SELECT ID,NAME,deleted
FROM Category;
END;
GO
/****** Object: StoredProcedure [dbo].[GetProducerDetails] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[GetProducerDetails]
AS
BEGIN
SELECT ID,NAME
FROM Producer;
END;
GO
/****** Object: StoredProcedure [dbo].[GetProducers] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetProducers]
AS
BEGIN
SELECT Id, Name, Country, deleted
FROM Producer
END;
GO
/****** Object: StoredProcedure [dbo].[GetProductDetails] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetProductDetails]
AS
BEGIN
SELECT Barcode, Name, CategoryID, ProducerID, Deleted
FROM Product;
END;
GO
/****** Object: StoredProcedure [dbo].[GetProductsOnReceipt] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetProductsOnReceipt]
AS
BEGIN
SELECT Barcode, Quantity, ReceiptId, Subtotal
FROM ProductOnReceipt
END
GO
/****** Object: StoredProcedure [dbo].[GetReceipts] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetReceipts]
AS
BEGIN
SELECT Id, ReleaseDate, CasherID, Total
FROM Receipt
END
GO
/****** Object: StoredProcedure [dbo].[GetSearchProducts] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetSearchProducts]
AS
BEGIN
select Product.name, Category.name,Producer.Name,Product.Barcode,Unit,SellingPrice,ExpiryDate,Quantity from Product inner join ProductStocks on Product.BarCode=ProductStocks.BarCode inner join Category on Category.id=Product.CategoryID inner join Producer on producer.ID=product.ProducerID;
END;
GO
/****** Object: StoredProcedure [dbo].[GetStockProducts] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetStockProducts]
AS
BEGIN
SELECT
p.Name,
ps.Barcode,
ps.Quantity,
ps.Unit,
ps.ExpiryDate,
ps.SellingPrice
FROM
ProductStocks ps
INNER JOIN
Product p ON ps.Barcode = p.Barcode
END;
GO
/****** Object: StoredProcedure [dbo].[GetStocks] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetStocks]
AS
BEGIN
SELECT
ps.ID,
ps.Barcode,
ps.Quantity,
ps.Unit,
ps.PurchasePrice,
ps.ExpiryDate,
ps.SupplyDate,
ps.SellingPrice,
ps.deleted
FROM
ProductStocks ps
END;
GO
/****** Object: StoredProcedure [dbo].[UpdateStock] Script Date: 5/26/2024 2:00:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UpdateStock]
@Barcode VARCHAR(50),
@QuantityChange INT
AS
BEGIN
UPDATE ProductStocks
SET Quantity = Quantity + @QuantityChange
WHERE Barcode = @Barcode;
END
GO
USE [master]
GO
ALTER DATABASE [SupermarketDB] SET READ_WRITE
GO