-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger_Passengerdetails.sql
67 lines (59 loc) · 2.57 KB
/
trigger_Passengerdetails.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
CREATE OR ALTER TRIGGER Passengerdetails
ON Passenger_A
AFTER INSERT,UPDATE
AS
BEGIN
DECLARE @Passportnumber CHAR(10), @Firstname VARCHAR(20),@Mint VARCHAR(5),@Lastname VARCHAR(20),@Gender VARCHAR(10),@Nationality VARCHAR(20),@Dateofbirth DATE, @Dateofissue DATE,
@Dateofexpire DATE,
@Legnumber CHAR(10),
@Airticketnumber CHAR(5),
@Guardian_Passport CHAR(10)
SELECT @Passportnumber=i.Passport_number,@Firstname=i.First_name,@Mint=i.Minit,@Lastname=i.Last_name,@Gender=i.Gender,@Nationality=i.Nationalty,@Dateofbirth=i.Date_of_Birth,
@Dateofissue=i.Date_of_Issue,
@Dateofexpire=i.Date_of_Expire,
@Legnumber=i.Leg_number,
@Airticketnumber=i.Air_ticket_number,
@Guardian_Passport=i.Guardian_passport_number FROM INSERTED i
IF ( @Passportnumber NOT LIKE 'M%')
BEGIN
PRINT 'Password number is in incorrect format'+CHAR(10)+'Passport Number should begin with "M"'
ROLLBACK
END IF(@Firstname= '' OR @Firstname is null)
BEGIN
PRINT 'You cannot leave First Name field Empty.'
ROLLBACK
END IF (@Gender= '' OR @Gender is null)
BEGIN
PRINT 'You cannot leave Gender field Empty.'
ROLLBACK
END IF (@Nationality= '' OR @Nationality is null)
BEGIN
PRINT 'You cannot leave Nationalty field Empty.'
ROLLBACK
END IF (@Dateofbirth= '' OR @Dateofbirth is null)
BEGIN
PRINT 'You cannot leave Date of Birth field Empty.'
ROLLBACK
END IF (@Dateofissue= '' OR @Dateofissue is null)
BEGIN
PRINT 'You cannot leave Date of issue field Empty.'
ROLLBACK
END IF (@Dateofexpire= '' OR @Dateofexpire is null)
BEGIN
PRINT 'You cannot leave Date of Expire field Empty.'
ROLLBACK
END IF (@Legnumber= '' OR @Legnumber is null)
BEGIN
PRINT 'You cannot leave Leg Number field Empty.'
ROLLBACK
END IF (@Airticketnumber= '' OR @Airticketnumber is null)
BEGIN
PRINT 'You cannot leave Air Ticket field Empty.'
ROLLBACK
END
ELSE
SELECT * FROM inserted i
END
/* Execution*/
insert into Passenger_A values ('M100123155','Devon','H','Jhona','Male','Mexican','1976-04-22','2014-08-16','2019-01-14','dpr1664556','max01',null)
insert into Passenger_A values ('M100179155','Devon','H','Jhona','','Mexican','1976-04-22','2014-08-16','2019-01-14','dpr1664556','max01',null)