Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

SQL CASE STUDIES

Anu has created the following relations in database Travels by providing Primary Key –
Foreign Key relationship.
Table: booking

Table: Flights

a) Which attribute is the Foreign Key in the given tables?


b) What is the degree of booking table and cardinality of Flights table?
c) Write a SQL query to delete the row from booking whose pname is “KAY”.
d) Anu wants to display the unique destinations from the booking table. Which keyword
need to be used by her in SELECT query:
i) UNIQUE ii)DISTINCT iii) HAVING iv)SET
e) Write a command to display the cardinality of the booking table?

Consider the following table named ‘data’ from a database ‘mobile’

(a) Write command to display the information of mobiles manufactured in 2013.


(b) What will the output of the following query.
SELECT COUNT(*) FROM data WHERE M_Price BETWEEN 4500 and 7500;
(c) Abhay want to remove all the rows of the ‘data’ table. Which command will he use from the
following:
a) DELETE FROM data; b) DROP TABLE data;
c) DROP DATABASE data; d) DELETE store FROM data;
(d) Which will be the most appropriate data type for column M_Id?
(e) Write a SQL command to display number of companies whose data is present in the table.

Consider the following table named ‘IPL’ from a database ‘sport’

(a) Write command used to select ‘sport’ database to perform SQL operations into that database.
(b) Write a command to increase number of matches played for ‘MI’ and ‘KKR’ by 1
(c) Write a command to display details of teams having negative NRR.
(d) What will be the most appropriate data type for NRR column?
(e) Which column would be most suitable for primary key?

Consider the following table named ‘IPL’ from a database ‘sport’

(a) What is primary key and foreign key in the above table?
(b) What is degree of natural join of above tables?
(c) Write a command to display products sold at Delhi.
(d) What will be the most appropriate data type for P_ID column?
(e) Write a command to insert a new row in ‘Product’ table with following data
P_ID = PP02, ProductName = “Body Wash”, Manufacturer = “PQR”. The price of the item is not yet
finalised so need to be NULL.

A department is considering to maintain their worker data using SQL to store the data. As a
database administer, Karan has decided that :

Name of the database - Department


Name of the table - WORKER
The attributes of WORKER are as follows:
WORKER_ID - character of size 3
FIRST_NAME – character of size 10
LAST_NAME– character of size 10
SALARY - numeric
JOINING_DATE – Date
DEPARTMENT – character of size 10

a) Write a query to create the given table WORKER.


b) Identify the attribute best suitable to be declared as a primary key.
c) Karan wants to increase the size of the FIRST_NAME column from 10 to 20 characters. Write an
appropriate query to change the size.
d) Karan wants to remove all the data from table WORKER from the database Department. Which
command will he use from the following:
i) DELETE FROM WORKER;
ii) DROP TABLE WORKER;
iii) DROP DATABASE Department;
iv) DELETE * FROM WORKER;

e) Write a query to display the Structure of the table WORKER, i.e. name of the attribute and their
respective data types.

You might also like