You are on page 1of 10

The following tables form part of a database

held in a relational DBMS:- Hotel (hotelNo,...


100% rating (3 votes) | like | dislike

Question:
The following tables form part of a database held in a relational DBMS:-

Hotel (hotelNo, hotelName, city)

Room (roomNo, hotelNo, type, price)

Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)

Guest (guestNo, guestName, guestAddress)

where
Hotel contains hotel details and hotelNo is the primary key;

Room contains room details for each hotel and (roomNo, hotelNo) forms the
primary key;

Booking contains details of the bookings and (hotelNo, guestNo, dateFrom)


forms the primary key;

and

Guest contains guest details and guestNo is the primary key.

Produce some sample tables for these relations that observe the relational
integrity rules. Suggest some general constraints that would be appropriate for
this schema.

Constraints:
A constraint is a set of rules that are applied to a column or combination of
columns. Constraints help prevent human errors while entering data into the
database, deleting tables, if there are any dependencies of data from another
table on that table. They also help preserve data integrity based on the business
rules set by the application. Database constraints help ensure data integrity
without the need to write an external program.

Answer and Explanation:


First, we need to create the sample tables:

CREATE TABLE Room (

RoomNO INTEGER,

HotelNo VARCHAR,

Type VARCHAR,

Price DECIMAL,

PRIMARY KEY (RoomNO, HotelNo),

FOREIGN KEY(HotelNO) REFERENCES Hotel );

insert into room values (501, 'fb01', 'single', $19);

insert into room values (601, 'fb01', 'double', $29);

create a table named hotel :

CREATE TABLE HOTEL (

hotelno

HOTELNO varchar (10),


HOTELNAME varchar (20),

CITY varchar (20),

PRIMARY KEY (HOTELNO)

insert into hotel values ('fb01', 'white', 'London');

insert into hotel values ('fb02', 'fairfax', 'USA');

create table guest (

guestNo numeric (5),

guestName varchar (20),

guestAddress varchar (50),

primary key (guestNo)

insert into visitor values (1001, 'babitha, '11815, VA');

insert into guest values (1002, 'sandeep', '9451, MD');

create table booking (

hotelno varchar (10),

guestNo numeric (5),

dateFrom date,

dateTo date,

roomNo numeric (5),

primary key (hotelno, guestNo, dateFrom),

foreign key (roomno, hotelno) REFERENCES room (roomno, hotelno),

foreign key (guestno) REFERENCES guest(guestno)

insert into booking values ('fb01', 1001, '11-03-16', '11-15-16', 501);

insert into booking values ('fb01', 1002, '12-03-16', '12-15-16', 601);

After creating the sample tables and inserting data, we obtain:


Sample Data

Some general constraints are:

SELECT COUNT (*) FROM hotel;

SELECT*FROM booking WHERE dateto is NULL;

Primary and Foreign keys are the constraints. Room is related to Hotel through
the HOTELNo. Therefore, the HOTELNo in Room should either be null or contain
the number of an existing hotel in the Hotel relation. In this case study, it would
probably be unacceptable to have a HOTELNo in Room with a null value.

Help improve Study.com. Report an Error

Become a member and unlock all Study Answers


Start today. Try it now

Create an account

Ask a question
Our experts can answer your tough homework and study questions.

Ask a question

Search Answers

Learn more about this topic:


0:23
4:25
Data Definition Language (DDL): Definition & Example
from
Chapter 5 / Lesson 1
63K
SQL commands used to create or use database structures are known as data
definition language (DDL). Explore the usage of the CREATE, DROP, and ALTER
commands, and the numerous functions of DDL.

Related to this Question


 Inspect the following logical relational database tables. Construct the likely underlying
conceptual model. 1st table Library Book Loan Event LoanID Date Time L1 1/21/2010
8:32 L2 1/21/2010 8:37 L3 1/

 Data Normalization: Tables TABCD below has its primary key attributes underlined:
TABCD (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) Decompose table TABCD into tables
in the third normal form usin

 Consider the following relational schema: Emp (eid, did, sal, hobby) Dept (did, dname,
floor, phone) Finance (did, budget, sales, expenses) Consider the following query:
SELECT d.dname, f.budget FROM

 1. This relational schema models a company schema with departments, employees,


and locations. Primary keys are underlined and foreign keys are indicated below each
relation. department(dno, dname, mgr

 Write the following queries in SQL, using the university schema. classroom(building,
room number, capacity) department(dept name, building, budget) course(course id,
title, dept name, credits) instruc

 Using the types of entities found in the colonial adventure tours database (trips,
guides, customers, and reservations). Create an example of a table that is in first
normal form but not in second nor

 Consider the following database. EMPLOYEE(Name, SSN, Salary, DNO, SupervisorSSN,


JobCode) DEPARTMENT(DNO, TotalSalary, ManagerSSN) STARTING_PAY(JobCode,
StartPay) Note that Dept_No in EMPLOYEE table i

 Given the following relational schemas: EMPLOYEE(SSN, NAME, SEX, DNUMBER)


DEPARTMENT(DNUMBER, DLOCATION) DLOCATION(DNUMBER, DLOCATION)
PROJECT(PNUMBER, PNAME, PLOCATION) WORKSON(SSN, PNUMBER, HOURS) 1

 Use SQL and the TAL Distributors database to complete the following exercises. 1. List
the item number, description, and price for all items. 2. List all rows and columns for
the complete ORDERS table
 A student-instructor-course database has the following schema:
S(S#,SNAME,MAJOR,CITY) I(I#,INAME,DEPT,CITY) C(C#,CNAME,UNITS)
E(S#,C#,GRADE) O(I#,C#,TIME,ROOM#) Use relational algebra expressions to a

 A foreign key must be which of the following? (a) match the field value of a primary key
in a related table. (b) be defined in all tables within the database. (c) be unique. (d) be
numeric.

 Data type helps a database management system (DBMS) to ________. a. retrieve


information. b. format data. c. allocate storage space. d. present the data in a useful
format. e. eliminate data duplication.

 Consider the following database schema for a UNIVERSITY database: -Students (name,
major, advisor) -Courses (code, department, name, units) -Schedule (course, term, year,
taughtby) -Enrollments (s

 Consider the following database. EMPLOYEE(Name, SSN, Salary, DNO, SupervisorSSN,


JobCode) DEPARTMENT(DNO, TotalSalary, ManagerSSN) STARTING_PAY(JobCode,
StartPay) Note that Dept_No in EMPLOYEE tab

 A table can be logically connected to another table by defining which of the following?
(a) common field. (b) primary key. (c) hyperlink. (d) foreign key.

 Data granularity refers to which of the following? a. The primary key in the dimension
table in the data warehouse. b. The foreign key in the dimension table in the data
warehouse. c. The level of det

 For the following, answer whether Tables are in 3NF? If not, state the normalization
rule that is violated. Rules can be: a. No multi-valued attribute. b. Not dependent on the
whole primary key. c. De

 A relational database is a group of which of the following? (a) common fields. (b)
related tables. (c) field values. (d) records.

 1. Consider the following database. EMPLOYEE(Name, SSN, Salary, DNO,


SupervisorSSN, JobCode) DEPARTMENT(DNO, TotalSalary, ManagerSSN)
STARTING_PAY(JobCode, StartPay) Note that Dept_No in EMPLOYEE

 1. Write SQL SELECT commands to answer the following queries. Consider the
following relational database for the Super Baseball League. It keeps track of teams in
the league, coaches and players on th

 Databases can have various objects, some of which are tables, queries, forms, and
views. Each of these has fields or columns. Describe the function of each of these
objects and how the fields or colum

 Of the following fields, which would be the most appropriate for the primary key in a
customer information table? Explain. (a) Customer name (b) Customer number (c)
Phone number (d) Customer address.

 Consider the following schema (Database tables): a) Suppliers (sid: integer, sname:
string, address: string) The "sid" is supplier's Id and "sname" is supplier's name b)
Parts (pid: integer, pname: st
 Write SQL SELECT commands to answer the following queries. Consider the following
relational database for the Super Baseball League. It keeps track of teams in the
league, coaches and players on the t

 Hands-on practice in database design is important. Use a relational DBMS to


implement the integrated REA data model presented in this chapter, or one of the
integrated data models from the homework pr

 The following is an example of a grade report for a student at TAMUCT. In order to


create this grade report, you have been hired to build a data model. 1. Identify entity
types. 2. Identify relation

 Observe the HAPPY INSURANCE DATABASE: This database will be used for the
following question citing tables from the HAPPY INSURANCE database. If a DBMS
enforces an UPDATE CASCADE option on the refere

 Given a customer table with fields for firstname and lastname, which of the following
will display the customer name as a single field in the format ?Jones, Tom? with a
heading? SELECT CONCAT(lastname

 Which of the following is true? (A) RDBMS can be in a soft state but key-value stores
cannot (B) Key-value stores can be in a soft state but RDBMS cannot (C) Both RDBMS
and key-value stores can be in soft states (D) Neither of RDBMS and key-value stores c

 Primary keys enforce which of the following? (a) referential integrity (b) entity integrity
(c) primary key relationships (d) foreign key relationships.

 The following SQL statement is an example of what type of join syntax? : SELECT
pcode, pdescript, vname FROM product, JOIN vendor ON product.vcode =
vendor.vcode;

 A relationship is an association between which of the following? (a) databases. (b)


objects. (c) fields. (d) entities.

 Which type of NoSQL database is Stardog an example of? (a) Graph database (b) Key-
value store (c) Document store.

 The provided ER diagram will be used for the following questions citing Eaglerun
Trucking Dispatcher ER Diagram. How many columns will the relation REGION have in
the relational schema mapped from the

 Q3: Write the following queries in SQL, using the university schem a.
classroom(building, room number, capacity) department(dept name, building, budget)
course(course id, title, dept name, credits) in

 Express the following constraints about the relations of Exercise 2.3.1, reproduced
here: Product (maker,model, type) PC (model, speed, ram, hd, price) Laptop (model,
speed, ram, hd, screen, price

 Explain the following crow's foot E-R diagram. Include entities, keys, attributes,
cardinality. What is the special type of entity represented by COMMISSION_RATE?
 Consider the following relations for a database that keeps track of automobile sales in
a car dealership (OPTION refers to some optional equipment installed on an
automobile): CAR(Serial_no, Model, M

 Please indicate what the highest normal form is for the following given relational
schemas: a. R(A, B, C, D) key: AB FD: A \rightarrow C, B \rightarrow D b. R(A, B, C, D)
key: AB FD: AB \rightarrow

 Consider the following three relations: TRAVEL_AGENT (name, age, salary) CUSTOMER
(name, departure_city, destination, journey_class) TRANSACTION (number, cust_name,
travel_agent_name, amount_paid)

 Develop an EER model for the following situation using the traditional EER notation, the
Visio notation, or the subtypes inside supertypes notation: Develop the complete data
model. Physicalize the

 1. To create a relationship between two tables, you need at least a data type. query.
hyperlink. primary key. 2. Which of the following does NOT describe a many-to-many
relationship? There must be a

 Emerging Electric wishes to create a database with the following entities and
attributes: Customer, with attributes Customer ID, Name, Address (Street, City, State,
Zip Code), and Telephone Lo

 Consider the bank database. branch(branch name, branch city, assets) customer
(customer name, customer street, customer city) loan (loan number, branch name,
amount) borrower (customer name, loan num

 Write a SQL query to return the average rating per genre, saved in a table called ?
query2? which has two attributes: name, rating. The database is as follows:

You might also like