I have the following database and wish to update the room
table. The table room
lists a room type that is either single, double or king, the price is the price of each room per night and the name in Hotel is the name of the hotel.
What I need to do is change all double rooms to king rooms which are in the Scotty Hotel and also increase their price by 10%.
I know how to update the price and the type when it is in a single table, but it seems here I need to join hotel and room on HNO and thus update. Nested query maybe?
create table Hotel (
HNo char(4),
Name varchar(20) not null,
Address varchar(50),
Constraint PK_Hotel Primary Key (HNo)
);
create table Room (
RNo char(4),
HNo char(4),
Type char(6) not null,
Price decimal (7,2),
Constraint PK_Room Primary Key (HNo, RNo),
Constraint FK_Room Foreign Key (HNo)
references Hotel (HNo)
);
create table Guest (
GNo char(4),
Name varchar(20) not null,
Address varchar(50),
Constraint PK_Guest Primary Key (GNo)
);
create table Booking (
HNo char(4),
GNo char(4),
DateFrom date,
DateTo date,
RNo char(4),
Constraint PK_Booking Primary Key (HNo, GNo, DateFrom),
Constraint FK_Booking Foreign Key (GNo)
references Guest (GNo),
Constraint FK_Booking_room Foreign Key (HNo, RNo)
references Room (HNo, RNo),
Constraint FK_Booking_hotel Foreign Key (HNo)
references Hotel (HNo)
);
I have two main questions:
Is it possible to do an update to a table, that requires a join?
I want to list guests via a view. Can I create a view which contains the hotel name and number of distinct guests that have ever stayed in the hotel?