DBMS & SQL
DBMS & SQL
advertisement
CREATE TABLE employee (name VARCHAR, id INTEGER)
What type of statement is this?
a) DML
b) DDL
c) View
d) Integrity constraint
View Answer
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.
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
View Answer
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?
advertisement
ADVERTISEMENT
ADVERTISEMENT
SELECT ________ dept_name
FROM instructor;
a) All
b) From
c) Distinct
d) Name
View Answer
Answer: c
Explanation: Distinct keyword selects only the entries that are
unique.
Sanfoundry Certification Contest of the Month is Live. 100+
Subjects. Participate Now!
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
View Answer
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 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) $
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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) _
View Answer
Answer: c
Explanation: || is the concatenation operator.
1. The union operation is represented by
a) ∩
b) U
c) –
d) *
View Answer
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
View Answer
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
View Answer
Answer: d
Explanation: None.
advertisement
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
View Answer
Answer: a
Explanation: Union all will combine all the tuples including
duplicates.
5.
Sanfoundry Certification Contest of the Month is Live. 100+
Subjects. Participate Now!
(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
View Answer
Answer: d
Explanation: Except keyword is used to ignore the values.
6. For like predicate which of the following is true.
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
View Answer
Answer: b
Explanation: Not null constraint removes the tpules of null values.
Sanfoundry Certification Contest of the Month is Live. 100+
Subjects. Participate Now!
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
View Answer
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
View Answer
Answer: d
Explanation: Unique is a constraint.
7.
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)
View Answer
Answer: b
Explanation: Avg() is used to find the mean of the values.
advertisement
3.
(SELECT course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010)
d)
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 course id
FROM SECTION
WHERE semester = ’Spring’ AND YEAR= 2010)
View Answer
Answer: a
Explanation: None.
UPDATE instructor
_____ salary= salary * 1.05;
Fill in with correct keyword to update the instructor relation.
a) Where
b) Set
c) In
d) Select
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
Answer: a
Explanation: The order of the two update statements is important. If
we changed the order of the two statements, an instructor with a
salary just under $100,000 would receive an over 8 percent raise.
SQL provides a case construct that we can use to perform both the
updates with a single update statement, avoiding the problem with
the order of updates.
1. The____condition allows a general predicate over the relations
being joined.
a) On
b) Using
c) Set
d) Where
View Answer
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
View Answer
Answer: c
Explanation: INNER JOIN: Returns all rows when there is at least one
match in BOTH tables.
3.
advertisement
SELECT *
FROM student JOIN takes USING (ID);
The above query is equivalent to
a)
SELECT *
FROM student OUTER JOIN takes USING (ID);
c)
SELECT *
FROM student LEFT OUTER JOIN takes USING (ID);
d) None of the mentioned
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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
View Answer
Answer: b
Explanation: None.
1. Which of the following creates a virtual relation for storing the
query?
a) Function
b) View
c) Procedure
d) None of the mentioned
View Answer
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”;
View Answer
Answer: c
Explanation: <query expression> is any legal query expression. The
view name is represented by v.
3.
advertisement
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
View Answer
Answer: c
Explanation: View names may appear in a query any place where a
relation name may appear.
Sanfoundry Certification Contest of the Month is Live. 100+
Subjects. Participate Now!
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
View Answer
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
View Answer
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
View Answer
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
View Answer
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:
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
View Answer
Answer: d
Explanation: Once a transaction has executed commit work, its
effects can no longer be undone by rollback work.
Subscribe Now: DBMS Newsletter | Important Subjects
Newsletters
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
View Answer
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
View Answer
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
View Answer
Answer: a
Explanation: None.
8. A transaction completes its execution is said to be
a) Committed
b) Aborted
c) Rolled back
d) Failed
View Answer
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
View Answer
Answer: c
Explanation: None.
10. ______ will undo all statements up to commit?
a) Transaction
b) Flashback
c) Rollback
d) Abort
View Answer
Answer: c
Explanation: Flashback will undo all the statements and Abort will
terminate the operation.
1. To include integrity constraint in an existing relation use :
a) Create table
b) Modify table
c) Alter table
d) Drop table
View Answer
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’
View Answer
Answer: b
Explanation: Positive is a value and not a constraint.
3.
advertisement
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(1008,Ross,Sales,20000);
View Answer
Answer: d
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.
advertisement
Here which one denotes the relation for which index is created?
a) StudentID_index
b) ID
c) StudentID
d) Student
View Answer
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
View Answer
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”.
Sanfoundry Certification Contest of the Month is Live. 100+
Subjects. Participate Now!
5. The user defined data type can be created using
a) Create datatype
b) Create data
c) Create definetype
d) Create type
View Answer
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
View Answer
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.
advertisement
ADVERTISEMENT
ADVERTISEMENT
GRANT 'privilege list'
ON 'user/role list'
TO 'relation name or view name';
c)