-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sql
892 lines (884 loc) · 66.1 KB
/
script.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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
/* ==Scripting Parameters==
Source Server Version : SQL Server 2016 (13.0.4001)
Source Database Engine Edition : Microsoft SQL Server Express Edition
Source Database Engine Type : Standalone SQL Server
Target Server Version : SQL Server 2017
Target Database Engine Edition : Microsoft SQL Server Standard Edition
Target Database Engine Type : Standalone SQL Server
*/
USE [master]
GO
/****** Object: Database [LibraryDB] Script Date: 11/8/2017 7:08:38 PM ******/
CREATE DATABASE [LibraryDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'LibraryDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\LibraryDB.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'LibraryDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\LibraryDB_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
ALTER DATABASE [LibraryDB] SET COMPATIBILITY_LEVEL = 130
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [LibraryDB].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [LibraryDB] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [LibraryDB] SET ANSI_NULLS OFF
GO
ALTER DATABASE [LibraryDB] SET ANSI_PADDING OFF
GO
ALTER DATABASE [LibraryDB] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [LibraryDB] SET ARITHABORT OFF
GO
ALTER DATABASE [LibraryDB] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [LibraryDB] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [LibraryDB] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [LibraryDB] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [LibraryDB] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [LibraryDB] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [LibraryDB] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [LibraryDB] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [LibraryDB] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [LibraryDB] SET DISABLE_BROKER
GO
ALTER DATABASE [LibraryDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [LibraryDB] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [LibraryDB] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [LibraryDB] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [LibraryDB] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [LibraryDB] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [LibraryDB] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [LibraryDB] SET RECOVERY SIMPLE
GO
ALTER DATABASE [LibraryDB] SET MULTI_USER
GO
ALTER DATABASE [LibraryDB] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [LibraryDB] SET DB_CHAINING OFF
GO
ALTER DATABASE [LibraryDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [LibraryDB] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
ALTER DATABASE [LibraryDB] SET DELAYED_DURABILITY = DISABLED
GO
ALTER DATABASE [LibraryDB] SET QUERY_STORE = OFF
GO
USE [LibraryDB]
GO
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
GO
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;
GO
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;
GO
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;
GO
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;
GO
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = PRIMARY;
GO
ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
GO
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET QUERY_OPTIMIZER_HOTFIXES = PRIMARY;
GO
USE [LibraryDB]
GO
/****** Object: Table [dbo].[BookGenres] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BookGenres](
[BookId] [int] NOT NULL,
[GenreId] [int] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[BookRentals] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BookRentals](
[UserId] [int] NOT NULL,
[BookId] [int] NOT NULL,
[RentalDate] [date] NOT NULL,
[ReturnDate] [date] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Books] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Books](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](50) NOT NULL,
[NoOfPages] [int] NOT NULL,
[StockCount] [int] NOT NULL,
[WriterId] [int] NOT NULL,
CONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED
(
[Id] 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].[Genres] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Genres](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Genres] PRIMARY KEY CLUSTERED
(
[Id] 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].[Roles] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Roles](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED
(
[Id] 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].[UserRoles] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserRoles](
[UserId] [int] NOT NULL,
[RoleId] [int] NOT NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Users] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](60) NOT NULL,
[Username] [nvarchar](60) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[Email] [nvarchar](30) NOT NULL,
[DateOfBirth] [date] NULL,
[DateJoined] [date] 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) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Writers] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Writers](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](60) NOT NULL,
[Biography] [nvarchar](300) NOT NULL,
[NoOfBooks] [int] NULL,
CONSTRAINT [PK_Writers] PRIMARY KEY CLUSTERED
(
[Id] 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].[BookGenres] ([BookId], [GenreId]) VALUES (10, 2)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (11, 2)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (13, 2)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (15, 2)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (16, 2)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (10, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (11, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (15, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (16, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (10, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (11, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (13, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (15, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (16, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (13, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (21, 6)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (21, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (21, 5)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (24, 7)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (24, 9)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (24, 4)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (2010, 3)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (2010, 6)
INSERT [dbo].[BookGenres] ([BookId], [GenreId]) VALUES (2010, 9)
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 10, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 11, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 13, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 10, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 11, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 11, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 13, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 10, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 11, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 16, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 16, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 13, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 15, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 11, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 13, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1069, 15, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1070, 13, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
INSERT [dbo].[BookRentals] ([UserId], [BookId], [RentalDate], [ReturnDate]) VALUES (1070, 27, CAST(N'2017-11-08' AS Date), CAST(N'2017-12-08' AS Date))
SET IDENTITY_INSERT [dbo].[Books] ON
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (10, N'The Silmarillion', 300, 20, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (11, N'The Lord of the Rings: The Fellowship of the Ring', 350, 20, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (13, N'The Lord of the Rings: The Two Towers', 400, 20, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (15, N'The Lord of the Rings: The Return of the King', 320, 20, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (16, N'The Hobbit', 300, 20, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (17, N'The Book of Lost Tales I', 340, 5, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (18, N'The Book of Lost Tales II', 310, 5, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (19, N'Milenium', 200, 10, 24)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (20, N'Plemić', 250, 10, 24)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (21, N'Operater', 300, 15, 24)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (22, N'The Prince of Mist', 450, 10, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (23, N'The Midnight Palace', 400, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (24, N'Marina', 350, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (25, N'The Shadow of the Wind', 420, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (26, N'The Angel''s Game', 400, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (27, N'The Prisoner of Heaven', 360, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (28, N'The Labyrinth of Spirits', 430, 5, 25)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (29, N'Dr Jekyll and Mr Hyde', 200, 15, 26)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (30, N'A Child''s Garden of Verses', 250, 5, 26)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (1014, N'dsad', 0, 0, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (1015, N'dsad', 0, 0, 20)
INSERT [dbo].[Books] ([Id], [Title], [NoOfPages], [StockCount], [WriterId]) VALUES (2010, N'Out of Time', 5, 5, 20)
SET IDENTITY_INSERT [dbo].[Books] OFF
SET IDENTITY_INSERT [dbo].[Genres] ON
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (2, N'Fantasy')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (3, N'Novel')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (4, N'Crime')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (5, N'Drama')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (6, N'Science fiction')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (7, N'Horror')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (8, N'Action')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (9, N'Adventure')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (10, N'Biography')
INSERT [dbo].[Genres] ([Id], [Name]) VALUES (11, N'Diaries')
SET IDENTITY_INSERT [dbo].[Genres] OFF
SET IDENTITY_INSERT [dbo].[Roles] ON
INSERT [dbo].[Roles] ([Id], [Name]) VALUES (24, N'User')
INSERT [dbo].[Roles] ([Id], [Name]) VALUES (26, N'Librarian')
INSERT [dbo].[Roles] ([Id], [Name]) VALUES (27, N'Administrator')
SET IDENTITY_INSERT [dbo].[Roles] OFF
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (1070, 24)
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (1069, 24)
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (1069, 26)
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (1069, 27)
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (2035, 24)
INSERT [dbo].[UserRoles] ([UserId], [RoleId]) VALUES (2035, 26)
SET IDENTITY_INSERT [dbo].[Users] ON
INSERT [dbo].[Users] ([Id], [Name], [Username], [Password], [Email], [DateOfBirth], [DateJoined]) VALUES (1069, N'Administrator', N'Administrator', N'25e4ee4e9229397b6b17776bfceaf8e7', N'admin@gmail.com', CAST(N'1993-10-30' AS Date), CAST(N'2017-11-01' AS Date))
INSERT [dbo].[Users] ([Id], [Name], [Username], [Password], [Email], [DateOfBirth], [DateJoined]) VALUES (1070, N'Dragan', N'Ilic Dragan', N'5f4dcc3b5aa765d61d8327deb882cf99', N'gagi@gmail.com', NULL, CAST(N'2017-11-02' AS Date))
INSERT [dbo].[Users] ([Id], [Name], [Username], [Password], [Email], [DateOfBirth], [DateJoined]) VALUES (2035, N'Librarian', N'Libman', N'45d0957b5daef354afdd3da14321a63d', N'lib@gmail.com', NULL, CAST(N'2017-11-06' AS Date))
SET IDENTITY_INSERT [dbo].[Users] OFF
SET IDENTITY_INSERT [dbo].[Writers] ON
INSERT [dbo].[Writers] ([Id], [Name], [Biography], [NoOfBooks]) VALUES (20, N'J.R.R. Tolken', N'John Ronald Reuel Tolkien, (3 January 1892 – 2 September 1973) was an English writer, poet, philologist, and university professor who is best known as the author of the classic high-fantasy works The Hobbit, The Lord of the Rings, and The Silmarillion.', 31)
INSERT [dbo].[Writers] ([Id], [Name], [Biography], [NoOfBooks]) VALUES (24, N'B.D. Benedikt', N'Božidar Damjanović Benedikt je kanadski pisac i filmski reditelj, rođen 7. aprila 1938. godine u malom hrvatskom mestu Vinici kod Varaždina.
Autor je više desetina klasičnih romana i naučno-popularnih knjiga objavljenih na srpskohrvatskom, poljskom, makedonskom, slovenačkom i engleskom jeziku.', 15)
INSERT [dbo].[Writers] ([Id], [Name], [Biography], [NoOfBooks]) VALUES (25, N'C.R. Safon', N'Carlos Ruiz Zafón (born 25 September 1964) is a Spanish novelist.', 20)
INSERT [dbo].[Writers] ([Id], [Name], [Biography], [NoOfBooks]) VALUES (26, N'R.L. Stevenson', N'Robert Louis Balfour Stevenson (13 November 1850 – 3 December 1894) was a Scottish novelist, poet, essayist, and travel writer. His most famous works are Treasure Island, Kidnapped, Strange Case of Dr Jekyll and Mr Hyde, and A Child''s Garden of Verses.', 30)
SET IDENTITY_INSERT [dbo].[Writers] OFF
SET ANSI_PADDING ON
GO
/****** Object: Index [NonClusteredIndex-20171030-175226] Script Date: 11/8/2017 7:08:39 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [NonClusteredIndex-20171030-175226] ON [dbo].[Users]
(
[Email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
/****** Object: Index [NonClusteredIndex-20171030-185826] Script Date: 11/8/2017 7:08:39 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [NonClusteredIndex-20171030-185826] ON [dbo].[Users]
(
[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[BookGenres] WITH CHECK ADD CONSTRAINT [FK_BooksGenres_Books] FOREIGN KEY([BookId])
REFERENCES [dbo].[Books] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BookGenres] CHECK CONSTRAINT [FK_BooksGenres_Books]
GO
ALTER TABLE [dbo].[BookGenres] WITH CHECK ADD CONSTRAINT [FK_BooksGenres_Genres] FOREIGN KEY([GenreId])
REFERENCES [dbo].[Genres] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BookGenres] CHECK CONSTRAINT [FK_BooksGenres_Genres]
GO
ALTER TABLE [dbo].[BookRentals] WITH CHECK ADD CONSTRAINT [FK_BookRentals_Books] FOREIGN KEY([BookId])
REFERENCES [dbo].[Books] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BookRentals] CHECK CONSTRAINT [FK_BookRentals_Books]
GO
ALTER TABLE [dbo].[BookRentals] WITH CHECK ADD CONSTRAINT [FK_BookRentals_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BookRentals] CHECK CONSTRAINT [FK_BookRentals_Users]
GO
ALTER TABLE [dbo].[Books] WITH CHECK ADD CONSTRAINT [FK_Books_Writers] FOREIGN KEY([WriterId])
REFERENCES [dbo].[Writers] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Books] CHECK CONSTRAINT [FK_Books_Writers]
GO
ALTER TABLE [dbo].[UserRoles] WITH CHECK ADD CONSTRAINT [FK_UserRoles_Roles] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Roles] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UserRoles] CHECK CONSTRAINT [FK_UserRoles_Roles]
GO
ALTER TABLE [dbo].[UserRoles] WITH CHECK ADD CONSTRAINT [FK_UserRoles_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UserRoles] CHECK CONSTRAINT [FK_UserRoles_Users]
GO
/****** Object: StoredProcedure [dbo].[BookDelete] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookDelete]
@Id int
AS
DELETE FROM Books WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[BookDeleteBookGenre] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookDeleteBookGenre]
@BookId int,
@GenreId int
AS
DELETE FROM BookGenres WHERE BookId = @BookId AND GenreId = @GenreId
GO
/****** Object: StoredProcedure [dbo].[BookGetAll] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookGetAll]
AS
SELECT * FROM Books
GO
/****** Object: StoredProcedure [dbo].[BookGetAllByWriter] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookGetAllByWriter]
@Id int
AS
SELECT * FROM Books WHERE WriterId = @Id
GO
/****** Object: StoredProcedure [dbo].[BookGetAllRentalsByUser] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookGetAllRentalsByUser]
@id int
AS
SELECT * FROM BookRentals
WHERE UserId = @id
GO
/****** Object: StoredProcedure [dbo].[BookGetById] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookGetById]
@Id int
AS
SELECT * FROM Books WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[BookInsert] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookInsert]
@Title nvarchar(50),
@NoOfPages int,
@StockCount int,
@WriterId int
AS
INSERT INTO Books (Title, NoOfPages, StockCount, WriterId) VALUES (@Title, @NoOfPages, @StockCount, @WriterId)
SELECT CAST(SCOPE_IDENTITY() AS int)
GO
/****** Object: StoredProcedure [dbo].[BookInsertBookGenre] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookInsertBookGenre]
@BookId int,
@GenreId int
AS
INSERT INTO BookGenres (BookId, GenreId) VALUES(@BookId, @GenreId)
GO
/****** Object: StoredProcedure [dbo].[BookSearch] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookSearch]
@TitleSearch nvarchar(50)
AS
SELECT * FROM Books WHERE Title LIKE @TitleSearch
GO
/****** Object: StoredProcedure [dbo].[BookUpdate] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[BookUpdate]
@Id int,
@Title nvarchar(50),
@NoOfPages int,
@StockCount int,
@WriterId int
AS
UPDATE Books SET Title = @Title, NoOfPages = @NoOfPages, StockCount = @StockCount, WriterId = @WriterId WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[GenreDelete] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreDelete]
@Id int
AS
DELETE FROM Genres WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[GenreGetAll] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreGetAll]
AS
SELECT * FROM Genres
GO
/****** Object: StoredProcedure [dbo].[GenreGetAllByBookId] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreGetAllByBookId]
@Id int
AS
SELECT * FROM Genres INNER JOIN BookGenres ON Genres.Id = BookGenres.GenreId WHERE BookId = @Id
GO
/****** Object: StoredProcedure [dbo].[GenreGetByBookId] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreGetByBookId]
@Id int
AS
SELECT BookId,Name FROM (Books
INNER JOIN BookGenres ON Books.Id = BookGenres.BookId)
INNER JOIN Genres ON GenreId = Genres.Id
WHERE BookId = @Id
GO
/****** Object: StoredProcedure [dbo].[GenreGetById] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreGetById]
@Id int
AS
SELECT * FROM Genres WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[GenreInsert] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreInsert]
@Name nvarchar(50)
AS
INSERT INTO Genres (Name) VALUES(@Name)
SELECT CAST(SCOPE_IDENTITY() AS int)
GO
/****** Object: StoredProcedure [dbo].[GenreSearch] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreSearch]
@Name nvarchar(50)
AS
SELECT * FROM Genres WHERE Name LIKE @Name
GO
/****** Object: StoredProcedure [dbo].[GenreUpdate] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GenreUpdate]
@Id int,
@Name nvarchar(50)
AS
UPDATE Genres SET Name = @Name WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[RoleDelete] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleDelete]
@Id int
AS
DELETE FROM Roles WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[RoleGetAll] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleGetAll]
AS
SELECT * FROM Roles
GO
/****** Object: StoredProcedure [dbo].[RoleGetAllByUser] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleGetAllByUser]
@Id int
AS
SELECT U.Id, R.Name FROM (Users U
INNER JOIN UserRoles ON U.Id = UserRoles.UserId)
INNER JOIN Roles R ON R.Id = RoleId
WHERE U.Id = @Id
GO
/****** Object: StoredProcedure [dbo].[RoleGetById] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleGetById]
@Id int
AS
SELECT * FROM Roles WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[RoleGetByName] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleGetByName]
@Name nvarchar(50)
AS
SELECT * FROM Roles WHERE Name = @Name
GO
/****** Object: StoredProcedure [dbo].[RoleGetByUser] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleGetByUser]
@Id int
AS
SELECT U.Id, R.Name FROM (Users U
INNER JOIN UserRoles ON U.Id = UserRoles.UserId)
INNER JOIN Roles R ON R.Id = RoleId
WHERE U.Id = @Id
GO
/****** Object: StoredProcedure [dbo].[RoleInsert] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleInsert]
@Name nvarchar(50)
AS
INSERT INTO Roles (Name) VALUES(@Name)
SELECT CAST(SCOPE_IDENTITY() AS int)
GO
/****** Object: StoredProcedure [dbo].[RoleUpdate] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[RoleUpdate]
@Id int,
@Name nvarchar(50)
AS
UPDATE Roles SET Name = @Name WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[UserDelete] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserDelete]
@Id int
AS
DELETE FROM Users WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[UserDeleteAllUserRoles] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserDeleteAllUserRoles]
@Id int
AS
DELETE FROM UserRoles WHERE UserId = @Id
GO
/****** Object: StoredProcedure [dbo].[UserDeleteBookRentals] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserDeleteBookRentals]
@UserId int,
@BookId int
AS
DELETE FROM BookRentals WHERE UserId = @UserId AND BookId = @BookId
GO
/****** Object: StoredProcedure [dbo].[UserDeleteUserRole] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserDeleteUserRole]
@UserId int,
@RoleId int
AS
DELETE FROM UserRoles WHERE UserId = @UserId AND RoleId = @RoleId
GO
/****** Object: StoredProcedure [dbo].[UserGetAll] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserGetAll]
AS
SELECT * FROM Users
GO
/****** Object: StoredProcedure [dbo].[UserGetByEmail] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserGetByEmail]
@email nvarchar(30)
AS
SELECT * FROM Users WHERE Email = @email
GO
/****** Object: StoredProcedure [dbo].[UserGetById] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserGetById]
@Id int
AS
SELECT * FROM Users WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[UserGetByLogin] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserGetByLogin]
@username nvarchar(60),
@email nvarchar(30),
@password nvarchar(50)
AS
SELECT * FROM Users WHERE (Username = @username OR Email = @email) AND Password = @password
GO
/****** Object: StoredProcedure [dbo].[UserInsert] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserInsert]
@Name nvarchar(60),
@UserName nvarchar(60),
@Password nvarchar(50),
@Email nvarchar(30),
@DateOfBirth Date,
@DateJoined Date
AS
BEGIN TRY
INSERT INTO Users (Name, UserName, Password, Email, DateOfBirth, DateJoined)
VALUES (@Name, @UserName, @Password, @Email ,@DateOfBirth ,@DateJoined)
SELECT CAST(SCOPE_IDENTITY() AS int)
END TRY
BEGIN CATCH
DECLARE @error NVARCHAR(255)
SET @error = (SUBSTRING( ERROR_MESSAGE(), CHARINDEX('(',ERROR_MESSAGE()), CHARINDEX(')',ERROR_MESSAGE())));
if(CHARINDEX('@',@error) > 0) SELECT -2;
ELSE SELECT -1;
END CATCH;
GO
/****** Object: StoredProcedure [dbo].[UserInsertBookRentals] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserInsertBookRentals]
@UserId int,
@BookId int,
@RentalDate Date,
@ReturnDate Date
AS
INSERT INTO BookRentals (UserId, BookId, RentalDate, ReturnDate) VALUES(@UserId, @BookId, @RentalDate, @ReturnDate)
GO
/****** Object: StoredProcedure [dbo].[UserInsertUserRole] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserInsertUserRole]
@UserId int,
@RoleId int
AS
INSERT INTO UserRoles (UserId, RoleId) VALUES(@UserId, @RoleId)
GO
/****** Object: StoredProcedure [dbo].[UserSearch] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserSearch]
@Name nvarchar(60)
AS
SELECT * FROM Users WHERE Name LIKE @Name
GO
/****** Object: StoredProcedure [dbo].[UserUpdate] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UserUpdate]
@Id int,
@Name nvarchar(60),
@Username nvarchar(60),
@Password nvarchar(50),
@Email nvarchar(30),
@DateOfBirth date,
@DateJoined date
AS
UPDATE Users SET Name = @Name, Username=@Username, Password=@Password, Email=@Email, DateOfBirth=@DateOfBirth, DateJoined = @DateJoined WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[WriterDelete] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterDelete]
@Id int
AS
DELETE FROM Writers WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[WriterGetAll] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterGetAll]
AS
SELECT * FROM Writers
GO
/****** Object: StoredProcedure [dbo].[WriterGetById] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterGetById]
@Id int
AS
SELECT * FROM Writers WHERE Id = @Id
GO
/****** Object: StoredProcedure [dbo].[WriterInsert] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterInsert]
@Name nvarchar(60),
@Biography nvarchar(300),
@NoOfBooks int
AS
INSERT INTO Writers (Name, Biography, NoOfBooks) VALUES(@Name, @Biography, @NoOfBooks)
SELECT CAST(SCOPE_IDENTITY() AS int)
GO
/****** Object: StoredProcedure [dbo].[WriterSearch] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterSearch]
@Name nvarchar(60)
AS
SELECT * FROM Writers WHERE Name LIKE @Name
GO
/****** Object: StoredProcedure [dbo].[WriterUpdate] Script Date: 11/8/2017 7:08:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[WriterUpdate]
@Id int,
@Name nvarchar(60),
@Bio nvarchar(300),
@Nob int
AS
UPDATE Writers SET Name = @Name, Biography = @Bio, NoOfBooks = @Nob WHERE Id = @Id
GO
USE [master]
GO
ALTER DATABASE [LibraryDB] SET READ_WRITE
GO