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
 General SQL Server Forums
 New to SQL Server Programming
 changing only the first record

Author  Topic 

MaryLee
Starting Member

8 Posts

Posted - 2010-11-10 : 15:48:43
Hello
I have the following sql statement which add booking Id in the room table when customer choose a room

"Update Room set bookinID=id where room_type=single"

the problem is this sql statement updates all records in the room table whose type are single " seems like the customer book all these rooms"

How can I make sql statement update only for the first record which vrify the above sql sataement.

Note: I have two tables one for booking and the other for room and I add bookingID as a foreign key in the Room table....

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-10 : 15:50:15
So you only want to update one row of the table?
Go to Top of Page

MaryLee
Starting Member

8 Posts

Posted - 2010-11-10 : 17:18:16
yes !!
but I can solve this problem if you tell me how can I make a relationship between two table one is Room and one is booking
this is for a hotel system should I take roomId as aforegn key to booking table or should I take bookingId as aforeign key to the room table.
this is the field of each table
Table Room (contains these fields)
RoomID
RoomType
RoomPrice

Table Booking (contains these fields)
BookingID
checkin
checkout
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-10 : 17:30:19
OK, I would think that the rooms don't change very often in a hotel (in fact, I can speak with a certain level of certainty on this). So, your booking table should have a foreign key field for RoomID. Each booking should have a RoomID, although I suppose one could make the case for it not having one right away.

Once you have that, you should be able to link the two.

Of course, you still can't update one row in the booking table by using roomID, unless roomID has only been used once so far. Otherwise, you need to know the bookingID.

Make sense?
Go to Top of Page

MaryLee
Starting Member

8 Posts

Posted - 2010-11-10 : 17:34:25
I do not Understand this

Of course, you still can't update one row in the booking table by using roomID, unless roomID has only been used once so far. Otherwise, you need to know the bookingID.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-11 : 05:00:02
Post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -