Database MCQ Number 00874

Database MCQ Set 1

1. What is the purpose of index in sql server
a) To enhance the query performance
b) To provide an index to a record
c) To perform fast searches
d) All of the mentioned

Answer

Answer: d [Reason:] A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes.

2. How many types of indexes are there in sql server?
a) 1
b) 2
c) 3
d) 4

Answer

Answer: b [Reason:] They are clustered index and non clustered index.

3. How non clustered index point to the data?
a) It never points to anything
b) It points to a data row
c) It is used for pointing data rows containing key values
d) None of the mentioned

Answer

Answer: c [Reason:] Nonclustered indexes have a structure separate from the data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value.

4. Which one is true about clustered index?
a) Clustered index is not associated with table
b) Clustered index is built by default on unique key columns
c) Clustered index is not built on unique key columns
d) None of the mentioned

Answer

Answer: b [Reason:] Nonclustered indexes have a structure separate from the data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value.

5. What is true about indexes?
a) Indexes enhance the performance even if the table is updated frequently
b) It makes harder for sql server engines to work to work on index which have large keys
c) It doesn’t make harder for sql server engines to work to work on index which have large keys
d) None of the mentioned

Answer

Answer: b [Reason:] Indexes tend to improve the performance.

6. Does index take space in the disk ?
a) It stores memory as and when required
b) Yes, Indexes are stored on disk
c) Indexes are never stored on disk
d) Indexes take no space

Answer

Answer: b [Reason:] Indexes take memory slots which are located on the disk.

7. What are composite indexes ?
a) Are those which are composed by database for its internal use
b) A composite index is a combination of index on 2 or more columns
c) Composite index can never be created
d) None of the mentioned

Answer

Answer: b [Reason:] A composite index is an index on two or more columns of a table.

8. If an index is _____ the metadata and statistics continue to exists
a) Disabling
b) Dropping
c) Altering
d) Both Disabling and Dropping

Answer

Answer: a [Reason:] A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes.

9. In ___ index instead of storing all the columns for a record together, each column is stored separately with all other rows in an index.
a) Clustered
b) Column store
c) Non clustered
d) Row store

Answer

Answer: b [Reason:] A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes.

10. A _____ index is the one which satisfies all the columns requested in the query without performing further lookup into the clustered index.
a) Clustered
b) Non Clustered
c) Covering
d) B-Tree

Answer

Answer: c [Reason:] A covered query is a query where all the columns in the query’s result set are pulled from non-clustered indexes.

Database MCQ Set 2

1. Which statements are correct regarding indexes?
a) When a table is dropped, the corresponding indexes are automatically dropped
b) For each DML operation performed, the corresponding indexes are automatically updated
c) A non-deferrable PRIMARY KEY or UNIQUE KEY constraint in a table automatically creates a unique index
d) All of the mentioned

Answer

Answer: d [Reason:] Indexes are used to access the data efficiently.

2. You executed the following SQL statements in the given order:

CREATE TABLE orders
(order_id NUMBER(3) PRIMARY KEY,
order_date DATE,
customer_idnumber(3));
 
INSERT INTO orders VALUES (100,'10-mar-2007,,222);
 
ALTER TABLE orders MODIFY order_date NOT NULL;
 
UPDATE orders SET customer_id=333;
 
DELETE FROM order;

The DELETE statement results in the following error:
ERROR at line 1: table or view does not exist
What would be the outcome?
a) All the statements before the DELETE statement would be rolled back
b) All the statements before the DELETE statement would be implicitly committed within the session
c) All the statements up to the ALTER TABLE statement would be committed and the outcome of UPDATE statement would be rolled back
d) All the statements up to the ALTER TABLE statement would be committed and the outcome of the UPDATE statement is retained uncommitted within the session

Answer

Answer: d [Reason:] Committing a transaction refers to making the changes to record in the database.

3. Evaluate the following statements:

CREATE TABLE digits
(id NUMBER(2),
description VARCHAR2(15));
INSERT INTO digits VALUES (1,'ONE);
UPDATE digits SET description ='TWO'WHERE id=1;
INSERT INTO digits VALUES (2 ,'TWO');
COMMIT;
DELETE FROM digits;
SELECT description FROM digits
VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE;

What would be the outcome of the above query?
a) It would not display any values
b) It would display the value TWO once
c) It would display the value TWO twice
d) It would display the values ONE, TWO, and TWO

Answer

Answer: c [Reason:] The VERSIONS BETWEEN clause of the SELECT statement is used to create a Flashback Version Query.

4. A non-correlated subquery can be defined as________
a) A set of sequential queries, all of which must always return a single value
b) A set of sequential queries, all of which must return values from the same table
c) A SELECT statement that can be embedded in a clause of another SELECT statement only
d) A set of one or more sequential queries in which generally the result of the inner query is used as the search value in the outer query

Answer

Answer: d [Reason:] A noncorrelated subquery is subquery that is independent of the outer query and it can executed on its own without relying on main outer query.

5. Which statement is true regarding synonyms?
a) Synonyms can be created for tables but not views
b) Synonyms are used to reference only those tables that are owned by another user
c) A public synonym and a private synonym can exist with the same name for the same table
d) The DROP SYNONYM statement removes the synonym, and the status of the table on which the synonym has been created becomes invalid

Answer

Answer: c [Reason:] A synonym is an alias or alternate name for a table, view, sequence, or other schema object. They are used mainly to make it easy for users to access database objects owned by other users.

6. SCOTT is a user in the database.

Evaluate the commands issued BY the DBA:
1 - CREATE ROLE mgr;
2 - GRANT CREATE TABLE, SELECT
ON oe. orders TO mgr;
3 - GRANT mgr, CREATE TABLE TO SCOTT;

Which statement is true regarding the execution of the above commands?
a) Statement 1 would not execute because the WITH GRANT option is missing
b) Statement 1 would not execute because the IDENTIFIED BY clause is missing
c) Statement 3 would not execute because role and system privileges cannot be granted together in a single GRANT statement
d) Statement 2 would not execute because system privileges and object privileges cannot be granted together in a single GRANT command

Answer

Answer: d [Reason:] The GRANT statement is used to give privileges to a specific user or role, or to all users, to perform actions on database objects.

7. OE and SCOTT are the users in the database. The ORDERS table is owned by OE. Evaluate the statements issued by the DBA in the following sequence:

CREATE ROLE r1;
GRANT SELECT, INSERT ON oe. orders TO r1;
GRANT r1 TO scott;
GRANT SELECT ON oe. orders TO scott;
REVOKE SELECT ON oe.orders FROM scott;

What would be the outcome after executing the statements?
a) SCOTT would be able to query the OE.ORDERS table
b) SCOTT would not be able to query the OE.ORDERS table
c) The REVOKE statement would remove the SELECT privilege from SCOTT as well as from the role R1
d) The REVOKE statement would give an error because the SELECT privilege has been granted to the role R1

Answer

Answer: a [Reason:] The REVOKE statement is used to remove privileges from a specific user or role, or from all users, to perform actions on database objects.

8. Given below are the SQL statements executed in a user session:

CREATE TABLE product
(pcode NUMBER(2),
pnameVARCHAR2(10));
INSERT INTO product VALUES(1, 'pen');
INSERT INTO product VALUES (2,'penci');
SAVEPOINT a;
UPDATE product SET pcode = 10 WHERE pcode = 1;
SAVEPOINT b;
DELETE FROM product WHERE pcode = 2;
COMMIT;
DELETE FROM product WHERE pcode=10;
ROLLBACK TO SAVEPOINT a;

Which statement describes the consequences?
a) No SQL statement would be rolled back
b) Both the DELETE statements would be rolled back
c) Only the second DELETE statement would be rolled back
d) Both the DELETE statements and the UPDATE statement would be rolled back

Answer

Answer: d [Reason:] The SAVEPOINT statement names and marks the current point in the processing of a transaction. With the ROLLBACK TO statement, savepoints undo parts of a transaction instead of the whole transaction.

9. Evaluate the following command:

CREATE TABLE employees (employee_id NUMBER(2) PRIMARY KEY, last_name VARCHAR2(25) NOT
NULL, department_id NUMBER(2), job_id VARCHAR2(8), salary NUMBER(10,2));
You issue the following command TO CREATE a VIEW that displays the IDs AND LAST names OF the sales staff IN the organization:
CREATE OR REPLACE VIEW sales_staff_vu AS SELECT employee_id, last_name job_id FROM employees
WHERE job_id LIKE 'SA_%' WITH CHECK OPTION;

Which statements are true regarding the above view?
a) It allows you to insert details of all new staff into the EMPLOYEES table
b) It allows you to delete the details of the existing sales staff from the EMPLOYEES table
c) It allows you to update the job ids of the existing sales staff to any other job id in the EMPLOYEES table
d) It allows you to insert the IDs, last

Answer

Answer: d [Reason:] SQL Create view syntax :

CREATE VIEW view_name AS
SELECT column_name(s)
FROM TABLE_NAME
WHERE condition.

10. EMPDET is an external table containing the columns EMPNO and ENAME. Which command would work in relation to the EMPDET table?

a) UPDATE empdet
SET ename = 'Amit'
WHERE empno = 1234;
b) DELETE FROM empdet
WHERE ename LIKE 'J%';
c) CREATE VIEW empvu
AS
SELECT* FROM empdept;
d) CREATE INDEX empdet_idx
ON empdet(empno);
Answer

Answer: c [Reason:] External tables are created using the SQL CREATE TABLE…ORGANIZATION EXTERNAL statement. When an external table is created, you specify type ,default directory, access parameters and location.

Database MCQ Set 3

1. To include integrity constraint in a existing relation use :
a) Create table
b) Modify table
c) Alter table
d) Drop table

Answer

Answer: c [Reason:] SYNTAX – alter table table-name add constraint , where constraint can be any constraint on the relation.

2. Which of the following is not a integrity constraint ?
a) Not null
b) Positive
c) Unique
d) Check ‘predicate’

Answer

Answer: b [Reason:] 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(1008,Ross,Sales,20000);

Answer

Answer: d [Reason:] 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.

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

Answer: a [Reason:] 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

Answer: b [Reason:] 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

Answer: b [Reason:] 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

Answer: c [Reason:] 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 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

Answer: a [Reason:] 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

Answer: c [Reason:] 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

Answer: c [Reason:] The information can be referred and obtained.

Database MCQ Set 4

1. The____condition allows a general predicate over the relations being joined.
a) On
b) Using
c) Set
d) Where

Answer

Answer: a [Reason:] 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

Answer: c [Reason:] 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) 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

Answer: a [Reason:] 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

Answer: c [Reason:] 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

Answer: d [Reason:] 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

Answer: d [Reason:] 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

Answer: d [Reason:] 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

Answer: b [Reason:] 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

Answer: a [Reason:] 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

Answer: b [Reason:] None.

Database MCQ Set 5

1. A_____ is a query that retrieves rows from more than one table or view:
a) Start
b) End
c) Join
d) All of the mentioned

Answer

Answer: c [Reason:] An SQL join clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as it is. A JOIN is a means for combining fields from two tables by using values common to each.

2. A condition is referred to as ____
a) Join in SQL
b) Join condition
c) Join in SQL & Condition
d) None of the mentioned

Answer

Answer: b [Reason:] An SQL join clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as it is. A JOIN is a means for combining fields from two tables by using values common to each.

3. Which oracle is the join condition is specified using the WHERE clause:
a) Oracle 9i
b) Oracle 8i
c) Pre-oracle 9i
d) Pre-oracle 8i

Answer

Answer: c [Reason:] Oracle 9i is a version of the Oracle Database. The i stands for “Internet” to indicate that 9i is “Internet ready”.

4. How many join types in join condition:
a) 2
b) 3
c) 4
d) 5

Answer

Answer: d [Reason:] INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, EQUIJOIN.

5. 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

Answer: d [Reason:] INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, EQUIJOIN are the types of joins.

6. Which product is returned in a join query have no join condition:
a) Equijoins
b) Cartesian
c) Both Equijoins and Cartesian
d) None of the mentioned

Answer

Answer: b [Reason:] A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of numerical coordinates.

7. Which is a join condition contains an equality operator:
a) Equijoins
b) Cartesian
c) Both Equijoins and Cartesian
d) None of the mentioned

Answer

Answer: a [Reason:] An equi-join is a specific type of comparator-based join, that uses only equality comparisons in the join-predicate.

8. Which join refers to join records from the write 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

Answer: b [Reason:] A right outer join will return all the rows that an inner join returns plus one row for each of the other rows in the second table that did not have a match in the first table. It is the same as a left outer join with the tables specified in the opposite order.

9. Which operation are allowed in a join view:
a) UPDATE
b) INSERT
c) DELETE
d) All of the mentioned

Answer

Answer: d [Reason:] The DELETE statement is used to delete rows in a table.The UPDATE statement is used to update existing records in a table.The INSERT INTO statement is used to insert new records in a table.

10. Which view that contains more than one table in the top-level FROM clause of the SELECT statement:
a) Join view
b) Datable join view
c) Updatable join view
d) All of the mentioned

Answer

Answer: c [Reason:] The DELETE statement is used to delete rows in a table.The UPDATE statement is used to update existing records in a table.The INSERT INTO statement is used to insert new records in a table.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.