-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyDb.sql
191 lines (139 loc) · 4.39 KB
/
MyDb.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
CREATE Table Users (
UserId int Identity primary key not null,
UserName varchar(30) not null ,
Password varchar(255) not null,
Name varchar(30) not null,
RoleId int not null Foreign Key REFERENCES Role(Id)
);
select * from Users
Create Table Role(
Id int identity primary key not null,
Name nvarchar(20) not null
);
select * from Role
Create Table Parks(
ParkId int identity(101,1) primary key not null,
Name nvarchar(20) not null,
Location nvarchar(50) not null,
Fee money not null
);
select * from Parks
CREATE TABLE Gate (
GateId int identity(200,1) primary key not null,
Name varchar(30) not null ,
ParkId int not null
CONSTRAINT FK_ParkID FOREIGN KEY(ParkId)
REFERENCES Parks(ParkId)
);
select * from Gate
CREATE TABLE Vehicle (
VId int identity(300,1) primary key not null,
VType varchar(30) not null ,
Name nvarchar(30) not null,
EntryCost money null,
Capacity nvarchar(20) null,
ParkId int not null Foreign Key REFERENCES Parks(ParkId)
);
select * from Vehicle
CREATE TABLE SafariDetail (
SafariId int identity(2000,1) primary key not null,
SafariName varchar(50) not null,
SafariDate Date not null,
SafariTime nvarchar(50) not null,
ParkId int not null Foreign key REFERENCES Parks(ParkId),
SafariCost Decimal not null
);
select * from SafariDetail
Create Table Tourist(
Id int identity(401,1) primary key not null,
Name varchar(30) not null ,
Gender varchar(10) not null,
DateOfBirth Date not null,
MobileNo nvarchar(10) not null,
City varchar(20) not null,
Country varchar(30) not null,
EmailId nvarchar(30) not null,
IdentityName nvarchar(20) not null,
IdentityNumber nvarchar(20) not null,
);
select * from Tourist
CREATE TABLE IdentityProof (
IdentityId int identity(11,1) primary key not null,
IdentityName varchar(50) not null
);
select * from IdentityProof
Create Table Booking(
Id int identity primary key not null,
Status nvarchar(20),
PId int not null Foreign key REFERENCES Parks(ParkId),
SafariId int not null Foreign key REFERENCES SafariDetail(SafariId),
GateId int not null Foreign key REFERENCES Gate(GateId),
VehicleId int not null Foreign key REFERENCES Vehicle(VId),
TotalCost money not null
);
select * from Booking
--=========================STORED PROCEDURES=========================================
Create or Alter Proc usp_ParkByLocation (@location nvarchar(30))
As
Begin
if(not exists(select Location from Parks where Location = @location))
begin
throw 50005,'No Parks to show',1;
end
select * from Parks
where Location = @location
end
exec usp_ParkByLocation Rajasthan
Create or Alter Proc usp_SafariByPark (@ParkId int)
As
Begin
if(not exists(select SafariName from SafariDetail where ParkId = @ParkId))
begin
throw 50005,'No Safari',1;
end
select * from SafariDetail
where ParkId = @ParkId
end
exec usp_SafariByPark 102
Create or Alter Proc usp_VehicleByPark (@ParkId int)
As
Begin
if(not exists(select Name, Capacity, EntryCost from Vehicle where ParkId = @ParkId and VType like '%Park'))
begin
throw 50005,'No Vehicles in this Park',1;
end
select VId,Name, Capacity, EntryCost from Vehicle
where ParkId = @ParkId and VType like '%Park'
end
exec usp_VehicleByPark 101
Create or Alter Proc usp_GateByPark (@ParkId int)
As
Begin
if(not exists(select GateId, Name from Gate where ParkId = @ParkId))
begin
throw 50005,'No Park or Gates',1;
end
select GateId,Name from Gate
where ParkId = @ParkId
end
exec usp_GateByPark 101
create or alter Proc usp_BookingStatus(@Id int)
As
Begin
if(not exists( select b.Id from Booking b where b.Id = @Id))
begin
throw 50005,'No Booking',1;
end
Select b.Id as BookingId, b.Status, p.Name as Parkname, v.Name as VehicleName, s.SafariName, s.SafariDate as Date, b.TotalCost from Booking b
join Parks p on b.PId = p.ParkId
join Vehicle v on b.VehicleId = v.VId
join SafariDetail s on b.SafariId = s.SafariId
where b.Id = @Id
Group by b.Id, b.Status ,p.Name, v.Name, s.SafariName, s.SafariDate, b.TotalCost
end
exec usp_BookingStatus 13
select * from AspNetUsers
select * from AspNetRoles
select * from AspNetUserRoles
insert into AspNetRoles values(NEWID(),'Admin','ADMIN',GETDATE())
insert into AspNetRoles values(NEWID(),'Tourist','TOURIST',GETDATE())