This set of Database Problems focuses on “Reduction to Relational Schemas”.
Consider the following relational schemas and answer the questions below
1. Which one of the following can be treated as a primary key in teaches relation ?
Explanation: Here Id is the only attribute that has to have unique entry.
2. The primary key in the section relation is
c) Both Course_id and Sec_id
d) All the attributes
Explanation: Both the entries has unique entry.
3. Select * from teaches where Sec_id = ‘CS-101’ ;
Which of the following Id is selected for the following query ?
d) Error message appears
Explanation: The value CS-101 matches the Course_id but not Id .
4. Select Id,Course_id,Building from section s and teaches t where t.year=2009 ;
Which of the following Id are displayed ?
c) Both 1003 and 1001
d) Error message appears
Explanation: Two rows are select in the above query.
5. The query which selects the Course_id ‘CS-101’ from the section relation is
a) Select Course_id from section where Building = ‘Richard’;
b) Select Course_id from section where Year = ‘2009’;
c) Select Course_id from teaches where Building = ‘Packyard’;
d) Select Course_id from section where Sec_id = ‘3’;
Explanation: The year ‘2009’ should be selected from the section relation.
CREATE TABLE SECTION (Course_id VARCHAR (8), Sec_id VARCHAR (8), Semester VARCHAR (6), YEAR NUMERIC (4,0), Building NUMERIC (15), PRIMARY KEY (course id, sec id, semester, YEAR), FOREIGN KEY (course id) REFERENCES course);
Which of the following has an error in the above create table for the relation section
a) Primary key (course id, sec id, semester, year)
b) Foreign key (course id) references course
c) Year numeric (4,0)
d) Building numeric (15)
Explanation: It should be replaced by Year Building varchar (15).
7. The relation with primary key can be created using
a) Create table instructor ( Id , Name)
b) Create table instructor ( Id , Name , primary key(name))
c) Create table instructor ( Id , Name , primary key (Id))
d) Create table instructor ( Id unique, Name )
Explanation: The value Name cannot be a primary key.
8. How can the values in the relation teaches be deleted ?
a) Drop table teaches;
b) Delete from teaches;
c) Purge table teaches;
d) Delete from teaches where Id =’Null’;
Explanation: Delete table cleans the entry from the table.
9. In the above teaches relation ” Select * from teaches where Year = ‘2010’” displays how many rows ?
Explanation: There are two tuples with year is 2009.
10. The relation changes can be got back using ________ command
Explanation: Purge deletes the table and delete cleans the table entry.
Sanfoundry Global Education & Learning Series – Database Management System.