GATE 2004
199 questions
MCQ 1991-mark 199
Questions 151–155 of 199
A table T1 in a relational database has the following rows and columns:
The following sequence of SQL statements was successfully executed on table T1.
The following sequence of SQL statements was successfully executed on table T1.
Update T1 set marks = marks + 5
Select avg(marks) from T1
What is the output of the select statement?
Answer: (C)
The update gives , so roll no. 4 stays NULL. The marks are now 15, 25, 35 and NULL.
avg ignores NULL values, so it averages only the three real values: .
Option (A) 18.75 is , which wrongly counts the NULL row as 0. The result is not NULL, because avg returns NULL only when every value is NULL.
Answer: (C)
avg ignores NULL values, so it averages only the three real values: .
Option (A) 18.75 is , which wrongly counts the NULL row as 0. The result is not NULL, because avg returns NULL only when every value is NULL.
Answer: (C)
A relational database contains two tables student and department in which student table has columns roll_no, name and dept_id and department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty tables:
Insert into department values (1, 'Mathematics')
Insert into department values (2, 'Physics')
Insert into student values (l, 'Navin', 1)
Insert into student values (2, 'Mukesh', 2)
Insert into student values (3, 'Gita', 1) How many rows and columns will be retrieved by the following SQL statement?
Select * from student, department
Answer: (D)
No joining condition is given. So the query returns the Cartesian product of the two tables.
Rows in the result = product of the row counts of the two tables:
Columns in the result = sum of the column counts of the two tables:
Answer: D.
Rows in the result = product of the row counts of the two tables:
Columns in the result = sum of the column counts of the two tables:
Answer: D.
The employee information in a company is stored in the relation
Employee (, sex, salary, deptName)
Consider the following SQL query
Employee (, sex, salary, deptName)
Consider the following SQL query
select deptName
from Employee
where sex = 'M'
group by deptName
having avg (salary) > (select avg (salary) from Employee) It returns the names of the department in whichAnswer: (D)
Follow the order in which the query is evaluated.
1. where sex = 'M' keeps only male employees, before any grouping.
2. group by deptName makes one group per department of these male employees, so avg(salary) in having is the average salary of the male employees in that department.
3. The inner query select avg(salary) from Employee has no condition, so it is the average salary of all employees in the company, male and female.
So the query returns the departments where the average salary of male employees is more than the average salary in the company.
(A) is wrong because the department average counts males only. (B) is wrong because the inner query averages all employees, not only males. (C) is wrong because the comparison is with the whole company, not with the same department.
Answer: (D)
1. where sex = 'M' keeps only male employees, before any grouping.
2. group by deptName makes one group per department of these male employees, so avg(salary) in having is the average salary of the male employees in that department.
3. The inner query select avg(salary) from Employee has no condition, so it is the average salary of all employees in the company, male and female.
So the query returns the departments where the average salary of male employees is more than the average salary in the company.
(A) is wrong because the department average counts males only. (B) is wrong because the inner query averages all employees, not only males. (C) is wrong because the comparison is with the whole company, not with the same department.
Answer: (D)
Consider the following relation schema pertaining to a students database:
Students (, name, address)
Enroll ( ,, coursename)
Where the primary keys are shown underlined. The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where '*' denotes natural join?
Students (, name, address)
Enroll ( ,, coursename)
Where the primary keys are shown underlined. The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where '*' denotes natural join?
Answer: (A)
In Students, rollno is the key, so each roll number appears at most once. The natural join matches tuples on the common attribute rollno. It is the only common attribute, because name, address and coursename are different names.
Maximum: each Enroll tuple matches at most one Students tuple, because rollno is unique in Students. So the result has at most 8 tuples.
Minimum: rollno in Enroll is taken as a foreign key that refers to Students, so every Enroll tuple finds exactly one matching student. So the result has at least 8 tuples.
Both counts are 8. 120 is not possible, because every result tuple comes from one Enroll tuple. 960 is , the size of a cross product, not a join on the key.
Answer: (A)
Maximum: each Enroll tuple matches at most one Students tuple, because rollno is unique in Students. So the result has at most 8 tuples.
Minimum: rollno in Enroll is taken as a foreign key that refers to Students, so every Enroll tuple finds exactly one matching student. So the result has at least 8 tuples.
Both counts are 8. 120 is not possible, because every result tuple comes from one Enroll tuple. 960 is , the size of a cross product, not a join on the key.
Answer: (A)
A relation Empdtl is defined with attributes empcode (unique), name, street, city, state and pincode. For any pincode, there is only one city and state. Also, for any given street, city and state, there is just one pincode. In normalization terms, Empdtl is a relation in
Answer: (B)
The relation is in , but it is not in .
To be in , every non prime attribute must be fully functionally dependent on the key. The key here is empcode, and it has only one attribute. So there is no partial dependency.
But there is a transitive dependency (pincode -> city, state). So the relation is not in .
Answer:
To be in , every non prime attribute must be fully functionally dependent on the key. The key here is empcode, and it has only one attribute. So there is no partial dependency.
But there is a transitive dependency (pincode -> city, state). So the relation is not in .
Answer: