SQL Queries Constraints and Triggers
SQL Queries Constraints and Triggers
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.
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.
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
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 >=.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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;
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..
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.
-- 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 ;
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.
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.
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.
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;
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.
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.
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.
-- 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.
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. 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.
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.
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 .
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.