0% found this document useful (0 votes)
24 views

SQL Queries Constraints and Triggers

Uploaded by

Mr. Phekdey
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

SQL Queries Constraints and Triggers

Uploaded by

Mr. Phekdey
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 38

2.

SQL : Queries, Constraints and Triggers


===

-- SQL Basics and SQL Data Definition ---


1. Which one of the following is used to define the structure of the relation,
deleting relations and relating schemas?
a) DML(Data Manipulation Langauge)
b) DDL(Data Definition Langauge)
c) Query
d) Relational Schema
Answer: b
Explanation: Data Definition language is the language which performs all the
operation in defining structure of relation.

2. Which one of the following provides the ability to query information from the
database and to insert tuples into, delete tuples from, and modify tuples in the
database?
a) DML(Data Manipulation Langauge)
b) DDL(Data Definition Langauge)
c) Query
d) Relational Schema
Answer: a
Explanation: DML performs the change in the values of the relation.

3.
CREATE TABLE employee (name VARCHAR, id INTEGER)
What type of statement is this?
a) DML
b) DDL
c) View
d) Integrity constraint
Answer: b
Explanation: Data Definition language is the language which performs all the
operation in defining structure of relation.
Subscribe Now: DBMS Newsletter | Important Subjects Newsletters

4.
SELECT * FROM employee
What type of statement is this?
a) DML
b) DDL
c) View
d) Integrity constraint
Answer: a
Explanation: Select operation just shows the required fields of the relation. So it
forms a DML.

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
Explanation: Varchar changes its length accordingly whereas char has a specific
length which has to be filled by either letters or spaces.

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
Explanation: Varchar changes its length accordingly whereas char has a specific
length which has to be filled by either letters or spaces.

7. To remove a relation from an SQL database, we use the ______ command.


a) Delete
b) Purge
c) Remove
d) Drop table
Answer: d
Explanation: Drop table deletes the whole structure of the relation .purge removes
the table which cannot be obtained again.

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
Explanation: Delete command removes the entries in the table.

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
Explanation: The values are manipulated. So it is a DML.

10. Updates that violate __________ are disallowed.


a) Integrity constraints
b) Transaction control
c) Authorization
d) DDL constraints
Answer: a
Explanation: Integrity constraint has to be maintained in the entries of the
relation.

-- SQL Queries ---


1.
Name
Annie
Bob
Callie
Derek
Which of these query will display the the table given above ?
a) Select employee from name
b) Select name
c) Select name from employee
d) Select employee
Answer: c
Explanation: The field to be displayed is included in select and the table is
included in the from clause.

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
Explanation: Distinct keyword selects only the entries that are unique.

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
Explanation: Where selects the rows on a particular condition. From gives the
relation which involves the operation.

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
Explanation: Where selects the rows on a particular condition. From gives the
relation which involves the operation. Since Instructor is a relation it has to
have from clause.

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
Explanation: None

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
Explanation: Join clause joins two tables by matching the common column.

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
Explanation: Here * is used to select all the fields of the relation.

8.
Employee_id Name Salary
1001 Annie 6000
1009 Ross 4500
1018 Zeith 7000
This is Employee table.
Which of the following employee_id will be displayed for the given query?
SELECT * FROM employee WHERE employee_id>1009;
a) 1009, 1001, 1018
b) 1009, 1018
c) 1001
d) 1018
Answer: d
Explanation: Greater than symbol does not include the given value unlike >=.

9. Which of the following statements contains an error?


a) Select * from emp where empid = 10003;
b) Select empid from emp where empid = 10006;
c) Select empid from emp;
d) Select empid where empid = 1009 and lastname = ‘GELLER’;
Answer: d
Explanation: This query do not have from clause which specifies the relation from
which the values has to be selected.

10. In the given query which of the keyword has to be inserted?


INSERT INTO employee _____ (1002,Joey,2000);
a) Table
b) Values
c) Relation
d) Field
Answer: b
Explanation: Value keyword has to be used to insert the values into the table.

-- Basic SQL Operations ---


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
Explanation: As keyword is used to rename.

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
Explanation: For any string operations single quoted(‘) must be used to enclose.

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
Explanation: The % character matches any substring.

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
Explanation: None.

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
Explanation: Specification of descending order is essential but it not for
ascending.

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
Explanation: None.

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;
View Answer
Answer: a
Explanation: SQL includes a between comparison operator to simplify where clauses
that specify that a value be less than or equal to some value and greater than or
equal to some other value.

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
Answer: b
Explanation: The asterisk symbol “ * ” can be usedin the select clause to denote
“all attributes.”

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
Explanation: The syntax of trim is Trim(s); where s-string.

10. _____ operator is used for appending two strings.


a) &
b) %
c) ||
d) _
Answer: c
Explanation: || is the concatenation operator.

-- Set Operations ---


1. The union operation is represented by
a) ∩
b) U
c) –
d) *
Answer: b
Explanation: Union operator combines the relations.

2. The intersection operator is used to get the _____ tuples.


a) Different
b) Common
c) All
d) Repeating
Answer: b
Explanation: Intersection operator ignores unique tuples and takes only common
ones.

3. The union operation automatically __________ unlike the select clause.


a) Adds tuples
b) Eliminates unique tuples
c) Adds common tuples
d) Eliminates duplicate
Answer: d
Explanation: None.

4. If we want to retain all duplicates, we must write ________ in place of union.


a) Union all
b) Union some
c) Intersect all
d) Intersect some
Answer: a
Explanation: Union all will combine all the tuples including duplicates.

5.
(SELECT course id
FROM SECTION
WHERE semester = ’Fall’ AND YEAR= 2009)
EXCEPT
(SELECT course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010);
This query displays
a) Only tuples from second part
b) Only tuples from the first part which has the tuples from second part
c) Tuples from both the parts
d) Tuples from first part which do not have second part
Answer: d
Explanation: Except keyword is used to ignore the values.

6. For like predicate which of the following is true.


i) % matches zero OF more characters.
ii) _ matches exactly one CHARACTER.
a) i-only
b) ii-only
c) i & ii
d) None of the mentioned
Answer: c
Explanation: The % wildcard matches zero or more characters, while the _ wildcard
matches exactly one character. Together, they offer flexibility and precision in
pattern matching within the like predicate.

7. The number of attributes in relation is called as its


a) Cardinality
b) Degree
c) Tuples
d) Entity
Answer: b
Explanation: None.

8. _____ clause is an additional filter that is applied to the result.


a) Select
b) Group-by
c) Having
d) Order by
Answer: c
Explanation: Having is used to provide additional aggregate filtration to the
query.

9. _________ joins are SQL server default


a) Outer
b) Inner
c) Equi
d) None of the mentioned
Answer: b
Explanation: It is optional to give the inner keyword with the join as it is
default.

10. The _____________ is essentially used to search for patterns in target string.
a) Like Predicate
b) Null Predicate
c) In Predicate
d) Out Predicate
Answer: a
Explanation: Like predicate matches the string in the given pattern.

-- Null Values Operations ---


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
Explanation: None.

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
Explanation: Null is used to represent the absence of a value.

3. The predicate in a where clause can involve Boolean operations such as and. The
result of true and unknown is_______ false and unknown is _____ while unknown and
unknown is _____
a) Unknown, unknown, false
b) True, false, unknown
c) True, unknown, unknown
d) Unknown, false, unknown
Answer: d
Explanation: None.

4.
SELECT name
FROM instructor
WHERE salary IS NOT NULL;
Selects
a) Tuples with null value
b) Tuples with no null values
c) Tuples with any salary
d) All of the mentioned
Answer: b
Explanation: Not null constraint removes the tpules of null values.

5. In an employee table to include the attributes whose value always have some
value which of the following constraint must be used?
a) Null
b) Not null
c) Unique
d) Distinct
Answer: b
Explanation: Not null constraint removes the tuples of null values.

6. Using the ______ clause retains only one copy of such identical tuples.
a) Null
b) Unique
c) Not null
d) Distinct
Answer: d
Explanation: Unique is a constraint.

7.
CREATE TABLE employee (id INTEGER,name VARCHAR(20),salary NOT NULL);
INSERT INTO employee VALUES (1005,Rach,0);
INSERT INTO employee VALUES (1007,Ross, );
INSERT INTO employee VALUES (1002,Joey,335);
Some of these insert statements will produce an error. Identify the statement.
a) Insert into employee values (1005,Rach,0);
b) Insert into employee values (1002,Joey,335);
c) Insert into employee values (1007,Ross, );
d) None of the mentioned
Answer: c
Explanation: Not null constraint is specified which means sone value (can include 0
also) should be given.

8. The primary key must be


a) Unique
b) Not null
c) Both Unique and Not null
d) Either Unique or Not null
Answer: c
Explanation: Primary key must satisfy unique and not null condition for sure.

9. You attempt to query the database with this command:


SELECT nvl (100 / quantity, NONE)
FROM inventory;
Why does this statement cause an error when QUANTITY values are null?
a) The expression attempts to divide by a null value
b) The data types in the conversion function are incompatible
c) The character string none should be enclosed in single quotes (‘ ‘)
d) A null value used in an expression cannot be converted to an actual value
Answer: a
Explanation: The expression attempts to divide by a null value is erroneous in sql.

10. The result of _____unknown is unknown.


a) Xor
b) Or
c) And
d) Not
Answer: d
Explanation: Since unknown does not hold any value the value cannot have a reverse
value.

-- Aggregate Functions and Nested Subqueries – 1 ---


1. Aggregate functions are functions that take a ___________ as input and return a
single value.
a) Collection of values
b) Single value
c) Aggregate value
d) Both Collection of values & Single value
Answer: a
Explanation: None.

2.
SELECT __________
FROM instructor
WHERE dept name= ’Comp. Sci.’;
Which of the following should be used to find the mean of the salary ?
a) Mean(salary)
b) Avg(salary)
c) Sum(salary)
d) Count(salary)
Answer: b
Explanation: Avg() is used to find the mean of the values.

3.
Note: Join free Sanfoundry classes at Telegram or Youtube
SELECT COUNT (____ ID)
FROM teaches
WHERE semester = ’Spring’ AND YEAR = 2010;
If we do want to eliminate duplicates, we use the keyword ______in the aggregate
expression.
a) Distinct
b) Count
c) Avg
d) Primary key
Answer: a
Explanation: Distinct keyword is used to select only unique items from the
relation.

4. All aggregate functions except _____ ignore null values in their input
collection.
a) Count(attribute)
b) Count(*)
c) Avg
d) Sum
Answer: b
Explanation: * is used to select all values including null.

5. A Boolean data type that can take values true, false, and________
a) 1
b) 0
c) Null
d) Unknown
Answer: d
Explanation: Unknown values do not take null value but it is not known.

6. The ____ connective tests for set membership, where the set is a collection of
values produced by a select clause. The ____ connective tests for the absence of
set membership.
a) Or, in
b) Not in, in
c) In, not in
d) In, or
Answer: c
Explanation: In checks, if the query has the value but not in checks if it does not
have the value.

7. Which of the following should be used to find all the courses taught in the Fall
2009 semester but not in the Spring 2010 semester .
a)
SELECT DISTINCT course id
FROM SECTION
WHERE semester = ’Fall’ AND YEAR= 2009 AND
course id NOT IN (SELECT course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010);
b)
SELECT DISTINCT course_id
FROM instructor
WHERE name NOT IN (’Fall’, ’Spring’);
c)
(SELECT course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010)
d)
SELECT COUNT (DISTINCT ID)
FROM takes
WHERE (course id, sec id, semester, YEAR) IN (SELECT course id, sec id, semester,
YEAR
FROM teaches
WHERE teaches.ID= 10101);
View Answer
Answer: a
Explanation: None.

8. The phrase “greater than at least one” is represented in SQL by _____


a) < all
b) < some
c) > all
d) > some
Answer: d
Explanation: >some takes atlest one value above it .

9. Which of the following is used to find all courses taught in both the Fall 2009
semester and in the Spring 2010 semester .
a)
SELECT course id
FROM SECTION AS S
WHERE semester = ’Fall’ AND YEAR= 2009 AND
EXISTS (SELECT *
FROM SECTION AS T
WHERE semester = ’Spring’ AND YEAR= 2010 AND
S.course id= T.course id);
b)
SELECT name
FROM instructor
WHERE salary > SOME (SELECT salary
FROM instructor
WHERE dept name = ’Biology’);
c)
SELECT COUNT (DISTINCT ID)
FROM takes
WHERE (course id, sec id, semester, YEAR) IN (SELECT course id, sec id, semester,
YEAR
FROM teaches
WHERE teaches.ID= 10101);
d)
(SELECT course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010)
View Answer
Answer: a
Explanation: None.

10. We can test for the nonexistence of tuples in a subquery by using the _____
construct.
a) Not exist
b) Not exists
c) Exists
d) Exist
Answer: b
Explanation: Exists is used to check for the existence of tuples.

-- Aggregate Functions and Nested Subqueries – 2 ---


1.
SELECT dept_name, ID, avg (salary)
FROM instructor
GROUP BY dept_name;
This statement IS erroneous because
a) Avg(salary) should not be selected
b) Dept_id should not be used in group by clause
c) Misplaced group by clause
d) Group by clause is not valid in this query
Answer: b
Explanation: Any attribute that is not present in the group by clause must appear
only inside an aggregate function if it appears in the select clause, otherwise the
query is treated as erroneous.

2. SQL applies predicates in the _______ clause after groups have been formed, so
aggregate functions may be used.
a) Group by
b) With
c) Where
d) Having
Answer: d
Explanation: The Having clause in SQL is used to apply predicates after groups have
been formed using the Group By clause. This allows aggregate functions to be used
and filters the grouped data based on specified conditions.

3. Aggregate functions can be used in the select list or the_______clause of a


select statement or subquery. They cannot be used in a ______ clause.
a) Where, having
b) Having, where
c) Group by, having
d) Group by, where
Answer: b
Explanation: To include aggregate functions having clause must be included after
where.

4. The ________ keyword is used to access attributes of preceding tables or


subqueries in the from clause.
a) In
b) Lateral
c) Having
d) With
Answer: b
Explanation:
Eg : SELECT name, salary, avg salary
FROM instructor I1, lateral (SELECT avg(salary) AS avg salary
FROM instructor I2
WHERE I2.dept name= I1.dept name);
Without the lateral clause, the subquery cannot access the correlation variable
I1 from the outer query.

5. Which of the following creates a temporary relation for the query on which it is
defined?
a) With
b) From
c) Where
d) Select
Answer: a
Explanation: The with clause provides a way of defining a temporary relation whose
definition is available only to the query in which the with clause occurs.

6.
WITH max_budget (VALUE) AS
(SELECT MAX(budget)
FROM department)
SELECT budget
FROM department, max_budget
WHERE department.budget = MAX budget.value;
In the query given above which one of the following is a temporary relation?
a) Budget
b) Department
c) Value
d) Max_budget
Answer: d
Explanation: With clause creates a temporary relation.

7. Subqueries cannot:
a) Use group by or group functions
b) Retrieve data from a table different from the one in the outer query
c) Join tables
d) Appear in select, update, delete, insert statements.
Answer: c
Explanation: None.

8. Which of the following is not an aggregate function?


a) Avg
b) Sum
c) With
d) Min
Answer: c
Explanation: With is used to create temporary relation and its not an aggregate
function.

9. The EXISTS keyword will be true if:


a) Any row in the subquery meets the condition only
b) All rows in the subquery fail the condition only
c) Both of these two conditions are met
d) Neither of these two conditions is met
Answer: a
Explanation: EXISTS keyword checks for existance of a condition.

10. How can you find rows that do not match some specified condition?
a) EXISTS
b) Double use of NOT EXISTS
c) NOT EXISTS
d) None of the mentioned
Answer: b
Explanation: None.

-- Modification of Database ---


1. A Delete command operates on ______ relation.
a) One
b) Two
c) Several
d) Null
Answer: a
Explanation: Delete can delete from only one table at a time.

2.
Delete from r where P;
The above command
a) Deletes a particular tuple from the relation
b) Deletes the relation
c) Clears all entries from the relation
d) All of the mentioned
Answer: a
Explanation: Here P gives the condition for deleting specific rows.

3. Which one of the following deletes all the entries but keeps the structure of
the relation.
a) Delete from r where P;
b) Delete from instructor where dept name= ’Finance’;
c) Delete from instructor where salary between 13000 and 15000;
d) Delete from instructor;
Answer: d
Explanation: Absence of condition deletes all rows.
4. Which of the following is used to insert a tuple from another relation?
a)
Note: Join free Sanfoundry classes at Telegram or Youtube
INSERT INTO course (course id, title, dept name, credits)
VALUES (’CS-437’, ’DATABASE Systems’, ’Comp. Sci.’, 4);
b)
INSERT INTO instructor
SELECT ID, name, dept name, 18000
FROM student
WHERE dept name = ’Music’ AND tot cred > 144;
c)
INSERT INTO course VALUES (’CS-437’, ’DATABASE Systems’, ’Comp. Sci.’, 4);
d) Not possible
Answer: b
Explanation: Using select statement in insert will include rows which are the
result of the selection.

5. Which of the following deletes all tuples in the instructor relation for those
instructors associated with a department located in the Watson building which is in
department relation.
a)
DELETE FROM instructor
WHERE dept_name IN 'Watson';
b)
DELETE FROM department
WHERE building='Watson';
c)
DELETE FROM instructor
WHERE dept_name IN (SELECT dept name
FROM department
WHERE building = ’Watson’);
d) None of the mentioned
Answer: c
Explanation: The query must include building=watson condition to filter the tuples.

6.
UPDATE instructor
_____ salary= salary * 1.05;
Fill in with correct keyword to update the instructor relation.
a) Where
b) Set
c) In
d) Select
Answer: b
Explanation: Set is used to update the particular value.

7. _________ are useful in SQL update statements, where they can be used in the set
clause.
a) Multiple queries
b) Sub queries
c) Update
d) Scalar subqueries
Answer: d
Explanation: None.

8. The problem of ordering the update in multiple updates is avoided using


a) Set
b) Where
c) Case
d) When
Answer: c
Explanation: The case statements can add the order of updating tuples.

9. Which of the following is the correct format for case statements.


a)
CASE
WHEN pred1 ... result1
WHEN pred2 ... result2
. . .
WHEN predn ... resultn
ELSE result0
END
b)
CASE
WHEN pred1 THEN result1
WHEN pred2 THEN result2
. . .
WHEN predn THEN resultn
ELSE result0
END
c)
CASE
WHEN pred1 THEN result1
WHEN pred2 THEN result2
. . .
WHEN predn THEN resultn
ELSE result0
d) All of the mentioned
Answer: b
Explanation: None.

10. Which of the following relation updates all instructors with salary over
$100,000 receive a 3 percent raise, whereas all others receive a 5 percent raise.
a)
UPDATE instructor
SET salary = salary * 1.03
WHERE salary > 100000;
UPDATE instructor
SET salary = salary * 1.05
WHERE salary <= 100000;
b)
UPDATE instructor
SET salary = salary * 1.05
WHERE salary < (SELECT avg (salary)
FROM instructor);
c)
UPDATE instructor
SET salary = CASE
WHEN salary <= 100000 THEN salary * 1.03
ELSE salary * 1.05
END
d) None of the mentioned
Answer: a
Explanation: The two sequential update statements will update the salary for the
given condition. Alternatively, SQL provides a case construct that we can use to
perform both the updates with a single update statement as follows:
UPDATE instructor
SET salary = CASE
WHEN salary > 100000 THEN salary * 1.03
ELSE salary * 1.05
END;

-- Join Expressions ---


1. The____condition allows a general predicate over the relations being joined.
a) On
b) Using
c) Set
d) Where
Answer: a
Explanation: On gives the condition for the join expression.

2. Which of the join operations do not preserve non matched tuples?


a) Left outer join
b) Right outer join
c) Inner join
d) Natural join
Answer: c
Explanation: INNER JOIN: Returns all rows when there is at least one match in BOTH
tables.

3.
SELECT *
FROM student JOIN takes USING (ID);
The above query is equivalent to
a)
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate
Now!
SELECT *
FROM student INNER JOIN takes USING (ID);
b)
SELECT *
FROM student OUTER JOIN takes USING (ID);
c)
SELECT *
FROM student LEFT OUTER JOIN takes USING (ID);
d) None of the mentioned
Answer: a
Explanation: Join can be replaced by inner join.

4. What type of join is needed when you wish to include rows that do not have
matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the mentioned
Answer: c
Explanation: An outer join does not require each record in the two joined tables to
have a matching record..

5. How many tables may be included with a join?


a) One
b) Two
c) Three
d) All of the mentioned
Answer: d
Explanation: Join can combine multiple tables.

6. Which are the join types in join condition:


a) Cross join
b) Natural join
c) Join with USING clause
d) All of the mentioned
Answer: d
Explanation: There are totally four join types in SQL.

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
Explanation: None.

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
Explanation: None.

-- Views ---
1. Which of the following creates a virtual relation for storing the query?
a) Function
b) View
c) Procedure
d) None of the mentioned
Answer: b
Explanation: Any such relation that is not part of the logical model, but is made
visible to a user as a virtual relation, is called a view.

2. Which of the following is the syntax for views where v is view name?
a) Create view v as “query name”;
b) Create “query expression” as view;
c) Create view v as “query expression”;
d) Create view “query expression”;
Answer: c
Explanation: <query expression> is any legal query expression. The view name is
represented by v.

3.
SELECT course_id
FROM physics_fall_2009
WHERE building= ’Watson’;
Here the tuples are selected from the view. Which one denotes the view?
a) Course_id
b) Watson
c) Building
d) physics_fall_2009
Answer: d
Explanation: In this SQL query, physics_fall_2009 is the name of the view from
which tuples are selected. A view in SQL is a virtual table which can be used to
access the data in the same way as a table.

4. Materialised views make sure that


a) View definition is kept stable
b) View definition is kept up-to-date
c) View definition is verified for error
d) View is deleted after specified time
Answer: b
Explanation: None.

5. Updating the value of the view


a) Will affect the relation from which it is defined
b) Will not change the view definition
c) Will not affect the relation from which it is defined
d) Cannot determine
Answer: a
Explanation: None.

6. SQL view is said to be updatable (that is, inserts, updates or deletes can be
applied on the view) if which of the following conditions are satisfied by the
query defining the view?
a) The from clause has only one database relation
b) The query does not have a group by or having clause
c) The select clause contains only attribute names of the relation and does not
have any expressions, aggregates, or distinct specification
d) All of the mentioned
Answer: d
Explanation: All of the conditions must be satisfied to update the view in sql.

7. Which of the following is used at the end of the view to reject the tuples which
do not satisfy the condition in where clause?
a) With
b) Check
c) With check
d) All of the mentioned
Answer: c
Explanation: Views can be defined with a with check option clause at the end of the
view definition; then, if a tuple inserted into the view does not satisfy the
view’s where clause condition, the insertion is rejected by the database system.

8. Consider the two relations instructor and department


Instructor:
ID Name Dept_name Salary
1001 Ted Finance 10000
1002 Bob Music 20000
1003 Ron Physics 50000
Department:
Dept_name Building Budget
Biology Watson 40000
Chemistry Painter 30000
Music Taylor 50000
Which of the following is used to create view for these relations together?
a)
CREATE VIEW instructor_info AS
SELECT ID, name, building
FROM instructor, department
WHERE instructor.dept name= department.dept name;
b)
CREATE VIEW instructor_info
SELECT ID, name, building
FROM instructor, department;
c)
CREATE VIEW instructor_info AS
SELECT ID, name, building
FROM instructor;
d)
CREATE VIEW instructor_info AS
SELECT ID, name, building
FROM department;
View Answer
Answer: a
Explanation: None.

9. For the view Create view instructor_info as


SELECT ID, name, building
FROM instructor, department
WHERE instructor.dept name= department.dept name;
If we insert tuple into the view as insert into instructor info values (’69987’,
’White’, ’Taylor’);
What will be the values of the other attributes in instructor and department
relations?
a) Default value
b) Null
c) Error statement
d) 0
Answer: b
Explanation: The values take null if there is no constraint in the attribute else
it is an Erroneous statement.

10.
CREATE VIEW faculty AS
SELECT ID, name, dept name
FROM instructor;
Find the error in this query.
a) Instructor
b) Select
c) View …as
d) None of the mentioned
Answer: d
Explanation: Syntax is – create view v as <query expression>;.

-- Transactions ---
1. A _________ consists of a sequence of query and/or update statements.
a) Transaction
b) Commit
c) Rollback
d) Flashback
Answer: a
Explanation: Transaction is a set of operation until commit.

2. Which of the following makes the transaction permanent in the database?


a) View
b) Commit
c) Rollback
d) Flashback
Answer: b
Explanation: Commit work commits the current transaction.

3. In order to undo the work of transaction after last commit which one should be
used?
a) View
b) Commit
c) Rollback
d) Flashback
Answer: c
Explanation: Rollback work causes the current transaction to be rolled back; that
is, it undoes all the updates performed by the SQL statements in the transaction.

4. Consider the following action:


TRANSACTION.....
Commit;
ROLLBACK;
What does Rollback do?
a) Undoes the transactions before commit
b) Clears all transactions
c) Redoes the transactions before commit
d) No action
Answer: d
Explanation: Once a transaction has executed commit work, its effects can no longer
be undone by rollback work.

5. In case of any shut down during transaction before commit which of the following
statement is done automatically?
a) View
b) Commit
c) Rollback
d) Flashback
Answer: c
Explanation: Once a transaction has executed commit work, its effects can no longer
be undone by rollback work.

6. In order to maintain the consistency during transactions, database provides


a) Commit
b) Atomic
c) Flashback
d) Retain
Answer: b
Explanation: By atomic, either all the effects of the transaction are reflected in
the database, or none are (after rollback).

7. Transaction processing is associated with everything below except


a) Conforming an action or triggering a response
b) Producing detail summary or exception report
c) Recording a business activity
d) Maintaining a data
Answer: a
Explanation: None.

8. A transaction completes its execution is said to be


a) Committed
b) Aborted
c) Rolled back
d) Failed
Answer: a
Explanation: A complete transaction always commits.

9. Which of the following is used to get back all the transactions back after
rollback?
a) Commit
b) Rollback
c) Flashback
d) Redo
Answer: c
Explanation: None.

10. ______ will undo all statements up to commit?


a) Transaction
b) Flashback
c) Rollback
d) Abort
Answer: c
Explanation: Flashback will undo all the statements and Abort will terminate the
operation.

-- Integrity Constraints ---


1. To include integrity constraint in an existing relation use :
a) Create table
b) Modify table
c) Alter table
d) Drop table
Answer: c
Explanation: SYNTAX – alter table table-name add constraint, where constraint can
be any constraint on the relation.

2. Which of the following is not an integrity constraint?


a) Not null
b) Positive
c) Unique
d) Check ‘predicate’
Answer: b
Explanation: Positive is a value and not a constraint.

3.
CREATE TABLE Employee(Emp_id NUMERIC NOT NULL, Name VARCHAR(20) , dept_name
VARCHAR(20), Salary NUMERIC, UNIQUE(Emp_id,Name));
INSERT INTO Employee VALUES(1002, Ross, CSE, 10000);
INSERT INTO Employee VALUES(1006,Ted,Finance, );
INSERT INTO Employee VALUES(1002,Rita,Sales,20000);
What will be the result of the query?
a) All statements executed
b) Error in create statement
c) Error in insert into Employee values(1006,Ted,Finance, );
d) Error in insert into Employee values(1002,Rita,Sales,20000);
Answer: a
Explanation: The not null specification prohibits the insertion of a null value for
the attribute.
The unique specification says that no two tuples in the relation can be equal on
all the listed attributes.

4.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate
Now!
CREATE TABLE Manager(ID NUMERIC,Name VARCHAR(20),budget NUMERIC,Details
VARCHAR(30));
Inorder to ensure that the value of budget is non-negative which of the following
should be used?
a) Check(budget>0)
b) Check(budget<0)
c) Alter(budget>0)
d) Alter(budget<0)
Answer: a
Explanation: A common use of the check clause is to ensure that attribute values
satisfy specified conditions, in effect creating a powerful type system.

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
Explanation: The foreign-key declaration specifies that for each course tuple, the
department name specified in the tuple must exist in the department relation.

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
Explanation: The delete “cascades” to the course relation, deletes the tuple that
refers to the department that was deleted.

7. Domain constraints, functional dependency and referential integrity are special


forms of _________
a) Foreign key
b) Primary key
c) Assertion
d) Referential constraint
Answer: c
Explanation: An assertion is a predicate expressing a condition we wish the
database to always satisfy.

8. Which of the following is the right syntax for the assertion?


a) Create assertion ‘assertion-name’ check ‘predicate’;
b) Create assertion check ‘predicate’ ‘assertion-name’;
c) Create assertions ‘predicates’;
d) All of the mentioned
Answer: a
Explanation: None.

9. Data integrity constraints are used to:


a) Control who is allowed access to the data
b) Ensure that duplicate records are not entered into the table
c) Improve the quality of data entered for a specific property (i.e., table column)
d) Prevent users from changing the values stored in the table
Answer: c
Explanation: None.

10. Which of the following can be addressed by enforcing a referential integrity


constraint?
a) All phone numbers must include the area code
b) Certain fields are required (such as the email address, or phone number) before
the record is accepted
c) Information on the customer must be known before anything can be sold to that
customer
d) When entering an order quantity, the user must input a number and not some text
(i.e., 12 rather than ‘a dozen’)
Answer: c
Explanation: The information can be referred to and obtained.

-- SQL Data Types and Schemas ---


1. Dates must be specified in the format
a) mm/dd/yy
b) yyyy/mm/dd
c) dd/mm/yy
d) yy/dd/mm
Answer: b
Explanation: yyyy/mm/dd is the default format in sql.

2. A ________ on an attribute of a relation is a data structure that allows the


database system to find those tuples in the relation that have a specified value
for that attribute efficiently, without scanning through all the tuples of the
relation.
a) Index
b) Reference
c) Assertion
d) Timestamp
Answer: a
Explanation: Index is the reference to the tuples in a relation.

3.
Create index studentID_index on student(ID);
Here which one denotes the relation for which index is created?
a) StudentID_index
b) ID
c) StudentID
d) Student
Answer: d
Explanation: The statement creates an index named studentID index on the attribute
ID of the relation student.

4. Which of the following is used to store movie and image files?


a) Clob
b) Blob
c) Binary
d) Image
Answer: b
Explanation: SQL therefore provides large-object data types for character data
(clob) and binary data (blob). The letters “lob” in these data types stand for
“Large OBject”.

5. The user defined data type can be created using


a) Create datatype
b) Create data
c) Create definetype
d) Create type
Answer: d
Explanation: The create type clause can be used to define new types.Syntax : create
type Dollars as numeric(12,2) final; .

6. Values of one type can be converted to another domain using which of the
following?
a) Cast
b) Drop type
c) Alter type
d) Convert
Answer: a
Explanation: Example of cast :cast (department.budget to numeric(12,2)). SQL
provides drop type and alter type clauses to drop or modify types that have been
created earlier.

7.
CREATE DOMAIN YearlySalary NUMERIC(8,2)
CONSTRAINT salary VALUE test __________;
In order to ensure that an instructor’s salary domain allows only values greater
than a specified value use:
a) Value>=30000.00
b) Not null;
c) Check(value >= 29000.00);
d) Check(value)
Answer: c
Explanation: Check(value ‘condition’) is the syntax.

8. Which of the following closely resembles Create view?


a) Create table . . .like
b) Create table . . . as
c) With data
d) Create view as
Answer: b
Explanation: The ‘create table . . . as’ statement closely resembles the create
view statement and both are defined by using queries. The main difference is that
the contents of the table are set when the table is created, whereas the contents
of a view always reflect the current query result.
9. In contemporary databases, the top level of the hierarchy consists of ______
each of which can contain _____
a) Catalogs, schemas
b) Schemas, catalogs
c) Environment, schemas
d) Schemas, Environment
Answer: a
Explanation: None.

10. Which of the following statements creates a new table temp instructor that has
the same schema as an instructor.
a) create table temp_instructor;
b) Create table temp_instructor like instructor;
c) Create Table as temp_instructor;
d) Create table like temp_instructor;
Answer: b
Explanation: None.

-- Authorizations ---
1. The database administrator who authorizes all the new users, modifies the
database and takes grants privilege is
a) Super user
b) Administrator
c) Operator of operating system
d) All of the mentioned
Answer: d
Explanation: The authorizations provided by the administrator to the user is a
privilege.

2. Which of the following is a basic form of grant statement?


a)
GRANT 'privilege list'
ON 'relation name or view name'
TO 'user/role list';
b)
GRANT 'privilege list'
ON 'user/role list'
TO 'relation name or view name';
c)
Note: Join free Sanfoundry classes at Telegram or Youtube
GRANT 'privilege list'
TO 'user/role list'
d)
GRANT 'privilege list'
ON 'relation name or view name'
ON 'user/role list';
View Answer
Answer: a
Explanation: The privilege list allows the granting of several privileges in one
command .

3. Which of the following is used to provide privilege to only a particular


attribute?
a) Grant select on employee to Amit
b) Grant update(budget) on department to Raj
c) Grant update(budget,salary,Rate) on department to Raj
d) Grant delete to Amit
Answer: b
Explanation: This grant statement gives user Raj update authorization on the budget
attribute of the department relation.

4. Which of the following statement is used to remove the privilege from the user
Amir?
a) Remove update on department from Amir
b) Revoke update on employee from Amir
c) Delete select on department from Raj
d) Grant update on employee from Amir
Answer: b
Explanation: revoke on from ;

5. Which of the following is used to provide delete authorization to instructor?


a)
CREATE ROLE instructor ;
GRANT DELETE TO instructor;
b)
CREATE ROLE instructor;
GRANT SELECT ON takes
TO instructor;
c)
CREATE ROLE instructor;
GRANT DELETE ON takes
TO instructor;
d) All of the mentioned
Answer: c
Explanation: The role is first created and the authorization is given on relation
takes to the role.

6. Which of the following is true regarding views?


a) The user who creates a view cannot be given update authorization on a view
without having update authorization on the relations used to define the view
b) The user who creates a view cannot be given update authorization on a view
without having update authorization on the relations used to define the view
c) If a user creates a view on which no authorization can be granted, the system
will allow the view creation request
d) A user who creates a view receives all privileges on that view
Answer: c
Explanation: A user who creates a view does not necessarily receive all privileges
on that view.

7. If we wish to grant a privilege and to allow the recipient to pass the privilege
on to other users, we append the __________ clause to the appropriate grant
command.
a) With grant
b) Grant user
c) Grant pass privelege
d) With grant option
Answer: d
Explanation: None.

8. In authorization graph, if DBA provides authorization to u1 which inturn gives


to u2 which of the following is correct?
a) If DBA revokes authorization from u1 then u2 authorization is also revoked
b) If u1 revokes authorization from u2 then u2 authorization is revoked
c) If DBA & u1 revokes authorization from u1 then u2 authorization is also revoked
d) If u2 revokes authorization then u1 authorization is revoked
Answer: c
Explanation: A user has an authorization if and only if there is a path from the
root of the authorization graph down to the node representing the user.

9. Which of the following is used to avoid cascading of authorizations from the


user?
a) Granted by current role
b) Revoke select on department from Amit, Satoshi restrict;
c) Revoke grant option for select on department from Amit;
d) Revoke select on department from Amit, Satoshi cascade;
Answer: b
Explanation: The revoke statement may specify restrict in order to prevent
cascading revocation. The keyword cascade can be used instead of restrict to
indicate that revocation should cascade.

10. The granting and revoking of roles by the user may cause some confusions when
that user role is revoked. To overcome the above situation
a) The privilege must be granted only by roles
b) The privilege is granted by roles and users
c) The user role cannot be removed once given
d) By restricting the user access to the roles
Answer: a
Explanation: The current role associated with a session can be set by executing set
role name. The specified role must have been granted to the user, else the set role
statement fails.

-- Access SQL From a Programming Language ---


1. Which of the following is used to access the database server at the time of
executing the program and get the data from the server accordingly?
a) Embedded SQL
b) Dynamic SQL
c) SQL declarations
d) SQL data analysis
Answer: b
Explanation: Embedded SQL, the SQL statements are identified at compile time using
a preprocessor. The preprocessor submits the SQL statements to the database system
for precompilation and optimization; then it replaces the SQL statements in the
application program with appropriate code and function calls before invoking the
programming-language compiler.

2. Which of the following header must be included in java program to establish


database connectivity using JDBC ?
a) Import java.sql.*;
b) Import java.sql.odbc.jdbc.*;
c) Import java.jdbc.*;
d) Import java.sql.jdbc.*;
Answer: a
Explanation: The Java program must import java.sql.*, which contains the interface
definitions for the functionality provided by JDBC.

3. DriverManager.getConnection(_______ , ______ , ______)


What are the two parameters that are included?
a) URL or machine name where server runs, Password, User ID
b) URL or machine name where server runs, User ID, Password
c) User ID, Password, URL or machine name where server runs
d) Password, URL or machine name where server runs, User ID
Answer: b
Explanation: The database must be opened first in order to perform any operations
for which this get connection method is used.
4. Which of the following invokes functions in sql?
a) Prepared Statements
b) Connection statement
c) Callable statements
d) All of the mentioned
Answer: c
Explanation: JDBC provides a Callable Statement interface that allows invocation of
SQL stored procedures and functions.

5. Which of the following function is used to find the column count of the
particular resultset?
a) getMetaData()
b) Metadata()
c) getColumn()
d) get Count()
Answer: a
Explanation: The interface ResultSet
has a method, getMetaData(), that returns a ResultSetMetaData object that contains
metadata about the result set. ResultSetMetaData, in turn, has methods to find
metadata information, such as the number of columns in the result, the name of a
specified column, or the type of a specified column.

6. Which of the following is a following statement is a prepared statements?


a) Insert into department values(?,?,?)
b) Insert into department values(x,x,x)
c) SQLSetConnectOption(conn, SQL AUTOCOMMIT, 0)
d) SQLTransact(conn, SQL ROLLBACK)
Answer: a
Explanation:? is used as a placeholder whose value can be provided later.

7. Which of the following is used as the embedded SQL in COBOL?


a) EXEC SQL <embedded SQL statement >;
b) EXEC SQL <embedded SQL statement > END-EXEC
c) EXEC SQL <embedded SQL statement >
d) EXEC SQL <embedded SQL statement > END EXEC;
Answer: b
Explanation: EXEC SQL <embedded SQL statement >; is normally in C.

8. Which of the following is used to distinguish the variables in SQL from the host
language variables?
a) .
b) –
c) :
d) ,
Answer: c
Explanation:
EXEC SQL
DECLARE c cursor FOR
SELECT ID, name
FROM student
WHERE tot cred > :credit amount;

9. The update statement can be executed in host language using


a) EXEC SQL update c;
b) EXEC SQL update c into :si, :sn;
c)
EXEC SQL
UPDATE instructor
SET salary = salary + 100
WHERE CURRENT OF c;
d) EXEC SQL update END-SQL
Answer: c
Explanation: The SQL can be terminated by ; to terminate the sentence.

10. Which of the following is used to access large objects from a database ?
a) setBlob()
b) getBlob()
c) getClob()
d) all of the mentioned
Answer: d
Explanation: None.

-- Functions and Procedures ---


1.
Create function dept count(dept_name varchar(20))
begin
declare d count integer;
select count(*) into d count
from instructor
where instructor.dept_name= dept_name
return d count;
end
Find the error in the the above statement.
a) Return type missing
b) Dept_name is mismatched
c) Reference relation is not mentioned
d) All of the mentioned
Answer: a
Explanation: Return integer should be given after create function for this
particular function.

2. For the function created in Question 1, which of the following is a proper


select statement ?
a)
SELECT dept name, budget
FROM instructor
WHERE dept COUNT() > 12;
b)
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate
Now!
SELECT dept name, budget
FROM instructor
WHERE dept COUNT(dept name) > 12;
c)
SELECT dept name, budget
WHERE dept COUNT(dept name) > 12;
d)
SELECT dept name, budget
FROM instructor
WHERE dept COUNT(budget) > 12;
View Answer
Answer: b
Explanation: The count of the dept_name must be checked for the displaying from
instructor relation.

3. Which of the following is used to input the entry and give the result in a
variable in a procedure?
a) Put and get
b) Get and put
c) Out and In
d) In and out
Answer: d
Explanation: Create procedure dept count proc(in dept name varchar(20), out d count
integer). Here in and out refers to input and result of procedure.

4.
Create procedure dept_count proc(in dept name varchar(20),
out d count integer)
begin
select count(*) into d count
from instructor
where instructor.dept name= dept count proc.dept name
end
Which of the following is used to call the procedure given above ?
a)
Declare d_count integer;
b)
Declare d_count integer;
call dept_count proc(’Physics’, d_count);
c)
Declare d_count integer;
call dept_count proc(’Physics’);
d)
Declare d_count;
call dept_count proc(’Physics’, d_count);
View Answer
Answer: b
Explanation: Here the ‘Physics’ is in variable and d_count is out variable.

5. The format for compound statement is


a) Begin ……. end
b) Begin atomic……. end
c) Begin ……. repeat
d) Both Begin ……. end and Begin atomic……. end
Answer: d
Explanation: A compound statement is of the form begin . . . end, and it may
contain multiple SQL statements between the begin and the end.A compound statement
of the form begin atomic . . . end ensures that all the statements contained within
it are executed as a single transaction.

6.
Repeat
sequence of statements;
__________________
end repeat
Fill in the correct option :
a) While Condition
b) Until variable
c) Until boolean expression
d) Until 0
Answer: c
Explanation: None.

7. Which of the following is the correct format for if statement?


a)
If boolean expression
then statement or compound statement
elseif boolean expression
then statement or compound statement
else statement or compound statement
end if
b)
If boolean expression
then statement or compound statement
elsif boolean expression
then statement or compound statement
else statement or compound statement
end if
c)
If boolean expression
then statement or compound statement
elif boolean expression
then statement or compound statement
else statement or compound statement
end if
d)
If boolean expression
then statement or compound statement
else
statement or compound statement
else statement or compound statement
end if
View Answer
Answer: a
Explanation: The conditional statements supported by SQL include if-then-else
statements by using this syntax. elif and elsif are not allowed.

8. A stored procedure in SQL is a___________


a) Block of functions
b) Group of Transact-SQL statements compiled into a single execution plan.
c) Group of distinct SQL statements.
d) None of the mentioned
Answer: b
Explanation: If it an atomic statement then the statements are in single
transaction.

9. Temporary stored procedures are stored in _________ database.


a) Master
b) Model
c) User specific
d) Tempdb
Answer: d
Explanation: None.

10. Declare out of classroom seats condition


DECLARE exit handler FOR OUT OF classroom seats
BEGIN
SEQUENCE OF statements
END
The above statements are used for
a) Calling procedures
b) Handling Exception
c) Handling procedures
d) All of the mentioned
Answer: b
Explanation: The SQL procedural language also supports the signaling of exception
conditions, and declaring of handlers that can handle the exception, as in this
code.

-- Triggers ---
1. A __________ is a special kind of a store procedure that executes in response to
certain action on the table like insertion, deletion or updation of data.
a) Procedures
b) Triggers
c) Functions
d) None of the mentioned
Answer: b
Explanation: Triggers are automatically generated when a particular operation takes
place.

2. Triggers are not supported for


a) Delete
b) Update
c) Views
d) Insert
Answer: c
Explanation: The triggers run after an insert, update or delete on a table. They
are not supported for views.

3. The CREATE TRIGGER statement is used to create the trigger. THE _____ clause
specifies the table name on which the trigger is to be attached. The ______
specifies that this is an AFTER INSERT trigger.
a) for insert, on
b) On, for insert
c) For, insert
d) None of the mentioned
Answer: b
Explanation: The triggers run after an insert, update or delete on a table. They
are not supported for views.

4. What are the after triggers?


a) Triggers generated after a particular operation
b) These triggers run after an insert, update or delete on a table
c) These triggers run after an insert, views, update or delete on a table
d) All of the mentioned
Answer: b
Explanation: AFTER TRIGGERS can be classified further into three types as: AFTER
INSERT Trigger, AFTER UPDATE Trigger, AFTER DELETE Trigger.

5. The variables in the triggers are declared using


a) –
b) @
c) /
d) /@
Answer: b
Explanation: Example : declare @empid int; where empid is the variable.

6. The default extension for an Oracle SQL*Plus file is:


a) .txt
b) .pls
c) .ora
d) .sql
Answer: d
Explanation: Example :None.

7. Which of the following is NOT an Oracle-supported trigger?


a) BEFORE
b) DURING
c) AFTER
d) INSTEAD OF
Answer: b
Explanation: Example: During trigger is not possible in any database.

8. What are the different in triggers?


a) Define, Create
b) Drop, Comment
c) Insert, Update, Delete
d) All of the mentioned
Answer: c
Explanation: Triggers are not possible for create, drop.

9. Triggers ________ enabled or disabled


a) Can be
b) Cannot be
c) Ought to be
d) Always
Answer: a
Explanation: Triggers can be manipulated.

10. Which prefixes are available to Oracle triggers?


a) : new only
b) : old only
c) Both :new and : old
d) Neither :new nor : old
Answer: c
Explanation: None.

-- Recursive Queries and Aggregation Features ---


1. Any recursive view must be defined as the union of two subqueries: a _______
query that is nonrecursive and a __________ query.
a) Base, recursive
b) Recursive, Base
c) Base, Redundant
d) View, Base
Answer: a
Explanation: First compute the base query and add all the resultant tuples to the
recursively defined view relation.

2. Ranking of queries is done by which of the following?


a) Group by
b) Order by
c) Having
d) Both Group by and Order by
Answer: b
Explanation: Order by clause arranges the values in ascending or descending order
where a default is ascending order.

3. In rank() function if one value is shared by two tuples then


a) The rank order continues as counting numbers
b) The rank order continues by leaving one rank in the middle
c) The user specifies the order
d) The order does not change
Answer: b
Explanation: Example. rank() over (order by (GPA) desc).

4. The __________ function that does not create gaps in the ordering.
a) Intense_rank()
b) Continue_rank()
c) Default_rank()
d) Dense_rank()
Answer: d
Explanation: For dense_rank() the tuples with the second highest value all get rank
2, and tuples with the third highest value get rank 3, and so on.

5.
Note: Join free Sanfoundry classes at Telegram or Youtube
SELECT ID, GPA
FROM student grades
ORDER BY GPA
____________;
Inorder to give only 10 rank on the whole we should use
a) Limit 10
b) Upto 10
c) Only 10
d) Max 10
Answer: a
Explanation: However, the limit clause does not support partitioning, so we cannot
get the top n within each partition without performing ranking; further, if more
than one student gets the same GPA, it is possible that one is included in the top
10, while another is excluded.

6. If there are n tuples in the partition and the rank of the tuple is r, then its
________ is defined as (r −1)/(n−1).
a) Ntil()
b) Cum_rank
c) Percent_rank
d) rank()
Answer: c
Explanation: Percent rank of a tuple gives the rank of the tuple as a fraction.

7. Inorder to simplify the null value confusion in the rank function we can specify
a) Not Null
b) Nulls last
c) Nulls first
d) Either Nulls last or first
Answer: d
Explanation: select ID, rank () over (order by GPA desc nulls last) as s rank from
student grades;.

8. Suppose we are given a view tot credits (year, num credits) giving the total
number of credits taken by students in each year. The query that computes averages
over the 3 preceding tuples in the specified sort order is
a)
SELECT YEAR, avg(num credits)
OVER (ORDER BY YEAR ROWS 3 preceding)
AS avg total credits
FROM tot credits;
b)
SELECT YEAR, avg(num credits)
OVER (ORDER BY YEAR ROWS 3 unbounded preceding)
AS avg total credits
FROM tot credits;
c) All of the mentioned
d) None of the mentioned
Answer: a
Explanation: Suppose that instead of going back a fixed number of tuples, we want
the window to consist of all prior years we use rows unbounded preceding.

9. The functions which construct histograms and use buckets for ranking is
a) Rank()
b) Newtil()
c) Ntil()
d) None of the mentioned
Answer: c
Explanation: For each tuple, ntile(n) then gives the number of the bucket in which
it is placed, with bucket numbers starting with 1.

10. The command ________________ such tables are available only within the
transaction executing the query and are dropped when the transaction finishes.
a) Create table
b) Create temporary table
c) Create view
d) Create label view
Answer: b
Explanation: None.

-- OLAP ---
1. OLAP stands for
a) Online analytical processing
b) Online analysis processing
c) Online transaction processing
d) Online aggregate processing
Answer: a
Explanation: OLAP is the manipulation of information to support decision making.

2. Data that can be modeled as dimension attributes and measure attributes are
called _______ data.
a) Multidimensional
b) Singledimensional
c) Measured
d) Dimensional
Answer: a
Explanation: Given a relation used for data analysis, we can identify some of its
attributes as measure attributes, since they measure some value, and can be
aggregated upon.Dimension attribute define the dimensions on which measure
attributes, and summaries of measure attributes, are viewed.

3. The generalization of cross-tab which is represented visually is ____________


which is also called as data cube.
a) Two dimensional cube
b) Multidimensional cube
c) N-dimensional cube
d) Cuboid
Answer: a
Explanation: Each cell in the cube is identified for the values for the three
dimensional attributes.

4. The process of viewing the cross-tab (Single dimensional) with a fixed value of
one attribute is
a) Slicing
b) Dicing
c) Pivoting
d) Both Slicing and Dicing
Answer: a
Explanation: The slice operation selects one particular dimension from a given cube
and provides a new sub-cube. Dice selects two or more dimensions from a given cube
and provides a new sub-cube.

5. The operation of moving from finer-granularity data to a coarser granularity (by


means of aggregation) is called a ________
a) Rollup
b) Drill down
c) Dicing
d) Pivoting
Answer: a
Explanation: The opposite operation—that of moving fromcoarser-granularity data to
finer-granularity data—is called a drill down.

6. In SQL the cross-tabs are created using


a) Slice
b) Dice
c) Pivot
d) All of the mentioned
Answer: a
Explanation: Pivot (sum(quantity) for color in (’dark’,’pastel’,’white’)).

7.
{ (item name, color, clothes size), (item name, color), (item name, clothes size),
(color, clothes size), (item name), (color), (clothes size), () }
This can be achieved by using which of the following ?
a) group by rollup
b) group by cubic
c) group by
d) none of the mentioned
Answer: d
Explanation: ‘Group by cube’ is used .

8. What do data warehouses support?


a) OLAP
b) OLTP
c) OLAP and OLTP
d) Operational databases
Answer: a
Explanation: None.

9.
SELECT item name, color, clothes SIZE, SUM(quantity)
FROM sales
GROUP BY rollup(item name, color, clothes SIZE);
How many grouping is possible in this rollup?
a) 8
b) 4
c) 2
d) 1
Answer: b
Explanation: { (item name, color, clothes size), (item name, color), (item name),
() }.
10. Which one of the following is the right syntax for DECODE?
a) DECODE (search, expression, result [, search, result]… [, default])
b) DECODE (expression, result [, search, result]… [, default], search)
c) DECODE (search, result [, search, result]… [, default], expression)
d) DECODE (expression, search, result [, search, result]… [, default])
Answer: d
Explanation: None.

You might also like