我在数据库中创建了三个表。乘客和航班表已经插入了信息。
create table IT260_AV.dbo.Passenger
( "Passport ID" nvarchar(20) not null,
"Lastname" nvarchar(50),
"Firstname" nvarchar(50),
"Nationality" int ,
"Telephone" nvarchar(20),
"Email" nvarchar(50),
"Birthdate" datetime,
"NumberOfChildren" int,
"PassportExpDate" datetime)
alter table IT260_AV.dbo.Passenger
add constraint Passenger_PK primary key clustered ("Passport ID")
create table IT260_AV.dbo.Flight
("FlightNo" int not null,
"Air Company" nvarchar (50),
"Departure Date" datetime,
"Departure Time" time,
"MaximumCapacity" int,
"BookingCapacity" int)
alter table IT260_AV.dbo.Flight
add constraint FlightNo_PK primary key clustered ("FlightNo")
create table IT260_AV.dbo.Booking
("Booking Number" nvarchar(20) not null,
"Flight Number" int not null,
"Passenger ID" nvarchar(20),
"SeatNo" int not null IDENTITY(1, 1),
constraint FK_FlightNumber foreign key ("Flight Number") references Flight("FlightNo"),
constraint FK_PassengerID foreign key ("Passenger ID") references Passenger("Passport ID") )
alter table IT260_AV.dbo.Booking
add constraint BookingNumber_PK primary key clustered ( "Booking Number")
我正在尝试创建一个程序,将乘客的护照和航班号作为输入,它将在预订表中创建新记录。
该程序应在完成预订之前检查航班的最大容量是否足够。如果不足,则应显示消息。此外,它应根据到期日检查给定的护照是否有效。
任何人都知道我应该做什么?
我尝试了这个,但我仍然收到错误:
create procedure sp_Booking_AV @PassengerPassport nvarchar(20), @Flightn0 int
as
begin
declare @Capacity int , @SeatAv int , @ExpDate date
set @Capacity = (select MaximumCapacity from Flight where FlightNo=@Flightn0)
set @SeatAv = (select max(SeatNo) from Booking)
set @ExpDate = (select PassportExpDate from Passenger where "Passport ID" = @PassengerPassport)
if (@SeatAv is null) set @SeatAv = 0
if(@SeatAv <=@Capacity)
if (@ExpDate>=Convert(date,getdate()))
insert into IT260_AV.dbo.Booking values (@PassengerPassport,@Flightn0)
else print 'The passport has been expired';
else print 'The fly is fool'
end
go