Database - SQL - Join - Excercieses: Mega Code
Database - SQL - Join - Excercieses: Mega Code
9
DataBase_SQL_JOIN_Excercieses
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
b) Natural join
c) Join with USING clause
d) All of the mentioned
Answer: d
7. How many join types in join condition:
a) 2 b) 3 c) 4 d) 5 Answer: d
Explanation: Types are inner join, left outer join, right outer join, full join, cross join.
8. Which join refers to join records from the right table that have no matching key in the left table
are include in the result set:
a) Left outer join
b) Right outer join
c) Full outer join
d) Half outer join
Answer: b
Explanation: RIGHT OUTER JOIN: Return all rows from the right table and the matched rows
from the left table.
9. The operation which is not considered a basic operation of relational algebra is
a) Join
b) Selection
c) Union
d) Cross product
Answer: a
10. In SQL the statement select * from R, S is equivalent to
a) Select * from R natural join S
b) Select * from R cross join S
c) Select * from R union join S
d) Select * from R inner join S
Answer: b
2. Here which of the following displays the unique values of the column?
SELECT ________ dept_name
FROM instructor;
a) All b) From c) Distinct d) Name
Answer: c
3. The ______ clause allows us to select only those rows in the result relation of the ____ clause
that satisfy a specified predicate.
a) Where, from
b) From, select
c) Select, from
d) From, where
Answer: a
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
4. The query given below will not give an error. Which one of the following has to
be replaced to get the desired output?
SELECT ID, name, dept name, salary * 1.1
WHERE instructor;
a) Salary*1.1
b) ID
c) Where
d) Instructor
Answer: c
5. The ________ clause is used to list the attributes desired in the result of a query.
a) Where
b) Select
c) From
d) Distinct
Answer: b
6. This Query can be replaced by which one of the following?
SELECT name, course_id
FROM instructor, teaches
WHERE instructor_ID= teaches_ID;
a) Select name,course_id from teaches,instructor where instructor_id=course_id;
b) Select name, course_id from instructor natural join teaches;
c) Select name, course_id from instructor;
d) Select course_id from instructor join teaches;
Answer: b
7.
SELECT * FROM employee WHERE salary>10000 AND dept_id=101;
Which of the following fields are displayed as output?
a) Salary, dept_id
b) Employee
c) Salary
d) All the field of employee relation
Answer: d
1.
SELECT name ____ instructor name, course id
FROM instructor, teaches
WHERE instructor.ID= teaches.ID;
Which keyword must be used here to rename the field name?
a) From
b) Rename
c) As
d) Join
Answer: c
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
2.
SELECT * FROM employee WHERE dept_name="Comp Sci";
In the SQL given above there is an error . Identify the error.
a) Dept_name
b) Employee
c) “Comp Sci”
d) From
Answer: c
3.
SELECT emp_name
FROM department
WHERE dept_name LIKE ’ _____ Computer Science’;
Which one of the following has to be added into the blank to select the dept_name which has
Computer Science as its ending string?
a) %
b) _
c) ||
d) $
Answer: a
4. ’_ _ _ ’ matches any string of ______ three characters. ’_ _ _ %’ matches any string of at
______ three characters.
a) Atleast, Exactly
b) Exactly, Atleast
c) Atleast, All
d) All, Exactly
Answer: b
5.
SELECT name
FROM instructor
WHERE dept name = ’Physics’
ORDER BY name;
By default, the order by clause lists items in ______ order.
a) Descending
b) Any
c) Same
d) Ascending
Answer: d
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
6.
SELECT *
FROM instructor
ORDER BY salary ____, name ___;
To display the salary from greater to smaller and name in ascending order which of the following
options should be used?
a) Ascending, Descending
b) Asc, Desc
c) Desc, Asc
d) Descending, Ascending
Answer: c
7.
SELECT name
FROM instructor
WHERE salary <= 100000 AND salary >= 90000;
This query can be replaced by which of the following ?
a)
SELECT name
FROM instructor
WHERE salary BETWEEN 90000 AND 100000;
b)
SELECT name
FROM employee
WHERE salary <= 90000 AND salary>=100000;
c)
SELECT name
FROM employee
WHERE salary BETWEEN 90000 AND 100000;
d)
SELECT name
FROM instructor
WHERE salary BETWEEN 100000 AND 90000;
Answer: a
8.
SELECT instructor.*
FROM instructor, teaches
WHERE instructor.ID= teaches.ID;
This query does which of the following operation?
a) All attributes of instructor and teaches are selected
b) All attributes of instructor are selected on the given condition
c) All attributes of teaches are selected on given condition
d) Only the some attributes from instructed and teaches are selected
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
9. In SQL the spaces at the end of the string are removed by _______ function.
a) Upper
b) String
c) Trim
d) Lower
Answer: c
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
5. The basic data type char(n) is a _____ length character string and varchar(n) is _____ length
character.
a) Fixed, equal
b) Equal, variable
c) Fixed, variable
d) Variable, equal
Answer: c
6. An attribute A of datatype varchar(20) has the value “Avi”. The attribute B of datatype
char(20) has value ”Reed”. Here attribute A has ____ spaces and attribute B has ____ spaces.
a) 3, 20
b) 20, 4
c) 20, 20
d) 3, 4
Answer: a
7. To remove a relation from an SQL database, we use the ______ command.
a) Delete
b) Purge
c) Remove
d) Drop table
Answer: d
8.
DELETE FROM r; //r - relation
This command performs which of the following action?
a) Remove relation
b) Clear relation entries
c) Delete fields
d) Delete rows
Answer: b
9.
INSERT INTO instructor VALUES (10211, ’Smith’, ’Biology’, 66000);
What type of statement is this?
a) Query
b) DML
c) Relational
d) DDL
Answer: b
10. Updates that violate __________ are disallowed.
a) Integrity constraints
b) Transaction control
c) Authorization
d) DDL constraints
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
1. A _____ indicates an absent value that may exist but be unknown or that may
not exist at all.
a) Empty tuple
b) New value
c) Null value
d) Old value
Answer: c
2. If the attribute phone number is included in the relation all the values need not be entered into
the phone number column. This type of entry is given as
a) 0
b) –
c) Null
d) Empty space
Answer: c
1. To include integrity constraint in an existing relation use :
a) Create table
b) Modify table
c) Alter table
d) Drop table
Answer: c
2. Which of the following is not an integrity constraint?
a) Not null
b) Positive
c) Unique
d) Check ‘predicate’
Answer: b
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
d) Alter(budget<0)
5. Foreign key is the one in which the ________ of one relation is referenced in another relation.
a) Foreign key
b) Primary key
c) References
d) Check constraint
Answer: b
6.
CREATE TABLE course
(...
FOREIGN KEY (dept name) REFERENCES department
. . . );
Which of the following is used to delete the entries in the referenced table when the tuple is
deleted in course table?
a) Delete
b) Delete cascade
c) Set null
d) All of the mentioned
Answer: b
1. The entity set person is classified as student and employee. This process is called _________
a) Generalization
b) Specialization
c) Inheritance
d) Constraint generalization
Answer: b
2. Which relationship is used to represent a specialization entity?
a) ISA b) AIS c) ONIS d) WHOIS
3. The refinement from an initial entity set into successive levels of entity subgroupings
represents a ________ design process in which distinctions are made explicit.
a) Hierarchy
b) Bottom-up
c) Top-down
d) Radical
Answer: c
4. There are similarities between the instructor entity set and the secretary entity set in the sense
that they have several attributes that are conceptually the same across the two entity sets: namely,
the identifier, name, and salary attributes. This process is called
a) Commonality
b) Specialization
c) Generalization
d) Similarity
Answer: c
Dr.Elmahdy
Mega Code(c)
9
DataBase_SQL_JOIN_Excercieses
6. A _____________ constraint requires that an entity belong to no more than one lower-level
entity set.
a) Disjointness
b) Uniqueness
c) Special
d) Relational
Answer: a
7. Consider the employee work-team example, and assume that certain employees participate in
more than one work team. A given employee may therefore appear in more than one of the team
entity sets that are lower level entity sets of employee. Thus, the generalization is _____________
a) Overlapping
b) Disjointness
c) Uniqueness
d) Relational
Answer: a
8. The completeness constraint may be one of the following: Total generalization or
specialization, Partial generalization or specialization. Which is the default?
a) Total
b) Partial
c) Should be specified
d) Cannot be determined
Answer: b
9. Functional dependencies are a generalization of
a) Key dependencies
b) Relation dependencies
c) Database dependencies
d) None of the mentioned
Answer: a
10. Which of the following is another name for a weak entity?
a) Child
b) Owner
c) Dominant
d) All of the mentioned
Answer: a
Dr.Elmahdy