(i) What will be the degree of student table?
(ii) What does ‘name’ represent in the above code snippet?
a) A table
b) A row
c) A column
d) A database
(iii) What is true about the following SQL statement?
SelecT * fROM student;
a) Display content of table ‘student’
b) Display column names and content of table ‘student’
c) Results in error as improper case has been used
d) Display only the column names of table ‘student’
(iv) What will be output of following query?
INSERT INTO student
VALUES (“Suhana”, 109, ‘F’),
VALUES (“Rivaan”, 102, ‘M’),
VALUES (“Atharv”, 103, ‘M’),
VALUES (“Rishika”, 105, ‘F’),
VALUES (“Garvit”, 104, ‘M’),
VALUES (“Shaurya”, 109, ‘M’);
(b) No Error
(c) Depends on Compiler
(d) Successful compilation of the query
(v) In the following query how many rows will be deleted?
DELETE student WHERE student_id =109;1
(b) All the rows where student ID is equal to 109
(c) No rows will be deleted
(d) 2 rows
3. Fill in the blanks
(i) _______ declares that an index in one table is related to that in another table.
(a) Primary key
(b) Foreign Key
(c) Composite Key
(d) Secondary Key
Ans: (b) Foreign Key
(Because as it name implies ‘Foreign’ which means that field is related to field of another table. The key which is Primary key in another related table is called ‘Foreign Key’)
(ii) The symbol Asterisk (*) in a select query retrieves _________.
(a) All data from the table
(b) Data of primary key only
(c) NULL data
(d) None of the mentioned
Ans: (d) None of the mentioned.
(Because * retrieves data of all attributes (columns) from a table not all data from table.)
(a) Retrieve movies information without mentioning their column names.
(b) List business done by the movies showing only MovieID, MovieName and BusinessCost.
(c) List the different categories of movies
(d) Find the net profit of each movie showing its ID, Name and Net Profit.
(Hint: NetProfit = BusinessCost –ProductionCost)
Make sure that the new column name is labeled as NetProfit. Is this column now a part of the MOVIE relation. If no, then what name coined for such columns? What can you say about the profit of a movie which has not yet released? Does your query result show profit as zero?
(e) List all movies with ProductionCost greater than 80,000 and less than 1,25000 showing ID, Name and ProductionCost.
(f) List all movies which fall in the category of Comedy or Action.
(g) List the movies which have not been released yet.
4. Suppose your school management has decided to conduct cricket matches between students of class XI and Class XII. Students of each class are asked to join any one of the four teams — Team Titan, Team Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be conducted between these teams. Help your sports teacher to do the following:
(a) Create a database “Sports”.
(b) Create a table “TEAM” with following considerations:
It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.
(c) Using table level constraint, make TeamID as primary key.
(e) As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table:
Row 1: (1, Team Titan)
Row 2: (2, Team Rockers)
Row 3: (3, Team Magnet)
Row 4: (4, Team Hurricane)
(g) Now create another table below. MATCH_DETAILS and insert data as shown in table. Choose appropriate domains and constraints for each attribute.
5. Using the sports database containing two relations (TEAM, MATCH_DETAILS), answer the following relational algebra queries.
(a) Retrieve the MatchID of all those matches where both the teams have scored > 70.
(b) Retrieve the MatchID of all those matches where FirstTeam has scored < 70 but SecondTeam has scored > 70.
(c) Find out the MatchID and date of matches played by Team 1 and won by it.
(d) Find out the MatchID of matches played by Team 2 and not won by it.
(e) In the TEAM relation, change the name of the relation to T_DATA. Also change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
(a) Populate these tables with appropriate data.
(b) Write SQL queries for the following.
(c) Find the names of students in Science Stream.
(d) What will be the primary keys of the three tables?
(e) What are the foreign keys of the three relations?
(f) Finds names of all the students studying in class ‘Commerce stream’ and are guided by same teacher, even if they are assigned different projects.
8. An organization ABC maintains a database EMP-DEPENDENT to record the following details about its employees and their dependents.
EMPLOYEE (AadhaarNo, Name, Address, Department, EmpID)
DEPENDENT (EmpID, DependentName, Relationship)
Use the EMP-DEPENDENT database to answer the following SQL queries:
(a) Find the names of employees with their dependent names.
Select E.Name, D.DependentName FROM EMPLOYEE E, DEPENDENT D
WHERE E.EmpID = D.EmpID;
(b) Find employee details working in a department, say, ‘PRODUCTION’.
(c) Find employee names having no dependent
(d) Find names of employees working in a department, say, ‘SALES’ and having exactly two dependents.
9. A shop called Wonderful Garments that sells school uniforms maintain a database SCHOOL_UNIFORM as shown below. It consisted of two relations — UNIFORM and PRICE. They made UniformCode as the primary key for UNIFORM relation. Further, they used UniformCode and Size as composite keys for PRICE relation. By analyzing the database schema and database state, specify SQL queries to rectify the following anomalies.
(a) The PRICE relation has an attribute named Price. In order to avoid confusion, write SQL query to change the
(b) M/S Wonderful Garments also keeps handkerchiefs of red color, medium size of 100 each. Insert this record in (c) When you used the above query to insert data, you were able to enter the values for handkerchief without entering its details in the UNIFORM relation. Make a provision so that the data can be entered in COST table only if it is already there in UNIFROM table.
(d) Further, you should be able to assign a new UCode to an item only if it has a valid Uname. Write a query to add appropriate constraint to the SCHOOL_ UNIFORM database.
(e) ALTER table to add the constraint that price of an item is always greater than zero.