469,610 Members | 2,118 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

relation & query


I'm relative new to sql and databases and the last few weeks I learned
myself a lot. I'm trying to make a hotel reservation application.

I have a database with a table Booking, a table Room, a table
RoomsPerBooking. So a booking contains date/time etc and a field
RoomsPerBookingID. The table RoomsPerBooking contains number of
persons, unitprice etc. and a field ID and a field RoomID. The table
Room contains data like name, notes etc.

now i have two questions:

First about relations:

The table Booking has relationship: PK table RoomsPerBooking - ID <-->
FK table Booking - RoomsPerBookingID.

The table RoomsPerBookingID has relationship: PK table Room - ID <-->
FK table RoomsPerBooking - RoomID

Is this relationset good for my purpose? I think it is, but I am not

The second question is:
How do I get available rooms per night

I came this far.... what are the "some statements"?
CREATE PROCEDURE dbo.GetAvailableRooms
@BeginDate DATETIME,

FROM Room room JOIN RoomsPerBooking roomsPerBooking
ON room.ID = roomsPerBooking.RoomID
--Some statements--
WHERE booking.FromDate <= @EndDate
AND booking.ToDate >= @BeginDate)
Jul 23 '05 #1
1 913
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear

Why do you have multiple names for the same data element? Why do you
use a singular name for a set of Rooms? Why did you use id and
room_id when the standard way of referencing a room is a "room number"?
Why do you use aliases that are the same as the base table names?

After you clean up the schema a bit, look at using a Calendar table.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by auke | last post: by
7 posts views Thread by Juris Krumins | last post: by
reply views Thread by ward | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.