Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 trigger

Author  Topic 

johnnyguy
Starting Member

2 Posts

Posted - 2004-04-14 : 09:51:23
hi i am creating a t sql database for a holiday company. Each holiday has a number of places available.These places are reduced as bookings are made in the booking table.

We need a trigger in the booking table to check if the number of places have reached their maximum and then display a message and stop the booking from being made.

i have inlcluded the tables with the relationship being many bookings to 1 holiday.

tblHoliday
Holiday_ID
Hotel_ID*
Event_ID*
instructor_ID*
Dsecription_Of_Holiday
Location
Start_Date
End_date
Minimum_No_Of_Bookings
No_Of_Places_Available
Nnumber_of_Bookings
price
cancelled

tblBooking
Customer_ID*
Holiday_ID*

Booking_date

Thanks
CJ

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-14 : 09:58:33
You need to have this logic in your "make booking" procedure, not a trigger. A trigger should be avoided unless absolutely necessary, or for archiving. This is not a case where it's necessary.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

johnnyguy
Starting Member

2 Posts

Posted - 2004-04-14 : 10:06:45
hi thanks for that, when u mean make booking procedure do u mean a check function? The problem is there are 2 tables tblBooking and tblHoliday involved.Do u mean we place a check in the tblBooking or tblHoliday?

Thanks
CJ
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-14 : 12:26:30
In your procedure to insert into booking:

INSERT tblBooking(
Customer_ID,
Holiday_ID,
Booking_date)

SELECT
c.Customer_ID,
h.Holiday_ID,
b.Booking_date
FROM
tblBooking b
INNER JOIN tblCustomer c ON b.Customer_ID = c.Customer_ID
INNER JOIN tblHoliday h ON b.Holiday_ID = b.Holiday_ID
WHERE
b.Booking_date = @booking_date
AND c.Customer_ID = @customer_id
AND h.Holiday_ID = @holiday_id
AND (COUNT(b.HolidayID)<h.No_Of_Places_Available
AND b.Booking_date BETWEEN h.Start_Date AND h.End_date)




MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -