Answered model mid term exam on ch. 8, 9, 10

advertisement

1.What is the full form of DDL in Oracle DB?

A.

Data Deleting Language

B.

Data Definition Language

C.

Data Delegating Language

D.

Dummy Data Language

Answer: B. DDL is one of the categories of SQL which stands for

Data Definition Language. Other SQL types are DML, DCL, and TCL.

2.DDL statements are used for which of the following Oracle

database objects?

A.

Tables

B.

Sub-queries

C.

Rows

D.

Columns

Answer: A. DDL contains commands like CREATE, ALTER and

ANALYZE which are used to CREATE TABLEs, view stored subprograms and packages in a database schema.

3.What is the basic unit of storage in Oracle Database that

contains data?

A.

View

B.

Column

C.

Query

D.

Table

Answer: D. Table is the basic unit of physical storage of data in

Oracle database.

4.Which of the below options best define a View?

A.

It is the shorter form of a table

B.

It is the logical representation of the subsets from one or more tables

C.

It has only one row and one column

D.

None of the above

Answer: B. View is a query which behaves like a window to format the data contained in one or more tables. Views do not contain any physical data but just a query which are created during runtime.

5. Which of the following are database objects?

A.

Table

B.

Sequence

C.

Synonym

D.

All of the above

Answer: D. Objects which are physically stored in database schema are database objects.

6. Which of the following database objects generate

numeric values?

A.

Table

B.

View

C.

Index

D.

Sequence

Answer: D. Sequence are used to generate unique values starting with a definite value and incremented by a specified factor. A sequence can be created to generate a series of integers. The values generated by a sequence can be stored in any table. A sequence is created with the CREATE SEQUENCE command.

7.Which of the following database objects gives an

alternative name to an object?

A.

Synonym

B.

Sequence

C.

View

D.

Index

Answer: A. A synonym provides a permanent alias for a database object. A public synonym is available to any database user. A private synonym is available only to the user who created it. A synonym is created by using the CREATE SYNONYM command. A

synonym is deleted by using the DROP SYNONYM command. Only a user with DBA privileges can drop a public synonym.

8.Which of the following database objects improves the

performance of some queries?

A.

Table

B.

Synonym

C.

View

D.

Index

Answer: D.

9. A table named 123_A is created for storing the number of employees in an organization. What is wrong in the name of

the table?

A.

The name of a table cannot start with a digit

B.

Nothing is wrong in this name.

C.

You cannot use an underscore while naming a table

D.

None of the above

Answer: A. As per the object naming conventions, table name must start with an alphabet.

9. What is true about the name of a table?

A.

A table can have a name which is used by some other object owned by the same user

B.

A sequence and a table can have same names

C.

A view and a table can have the same name

D.

A table name must not duplicate the name of another object owned by the same user

Answer: D. By virtue of namespace, a table name cannot be same as any other schema objects. Schema objects which share the same namespace include tables, views, sequences, private synonyms, stored procedures, stored functions, packages, materialized views, and user-defined types.

10. You create a table and name it as COUNT. What will be

the outcome of CREATE TABLE script?

A.

The table will not be created

B.

The table will be created and an underscore will be added automatically to the name COUNT_

C.

An ORA error will be thrown

D.

The table COUNT will be created without any errors

Answer: A, C. You cannot create a table with the name same as an Oracle Server reserved word.

11. What among the following are the pre-requisites for

creating a table?

A.

CREATE TABLE privilege

B.

Storage space

C.

Data in the table

D.

None of the above

Answer: A, B. A user must possess the CREATE TABLE privilege and must have sufficient space to allocate the initial extent to the table segment.

12. Pick the element which you must specify while creating

a table.

A.

Column name

B.

Column Data type

C.

Column size

D.

All of the above

Answer: D. A table must have atleasr one column, its data type specification, and precision (if required).

13. A user named "Kevin" wants to access a table which is owned by another user named "Jonathan". Which of the

following will work for Kevin?

A.

Select * from Kevin.employees;

B.

Select * from jonathan.employees;

C.

Either of A or B

D.

None of the above

Answer: B.

14. Which of the following command is used to see the

structure of a table?

A.

UPDATE

B.

SHOW

C.

DESCRIBE

D.

SPOOL

Answer: C. DESCRIBE is a SQL*Plus command to list the structure of the table.

15. Which of the following commands will drop table employees?

A.

DROP employees

B.

DROP TABLE employees

C.

TRUNCATE employees

D.

None of the above

Answer: B.

16. What is true about creating a table?

A.

While creating a table, each column should be assigned a data type

B.

Data type assignment to columns is not mandatory

C.

A data type has to be assigned to a table and not to a column

D.

None of the above

Answer: A. Each column must possess behavioral attributes like data types and precision in order to build the structure of the table.

17. What will happen if the inserted value is of a smaller

length as defined for a VARCHAR2 data type column?

A.

It will throw an ORA error

B.

It will get inserted successfully and the value will take up as much space as it needs.

C.

It will get inserted and the remaining space will be padded with spaces

D.

None of the above

Answer: B. VARCHAR2 contains variable length character data.

18. What will happen if the inserted value is of a smaller

length as defined for a CHAR data type column?

A.

It will throw an ORA error

B.

It will get inserted successfully and the value will take up as much space as it needs.

C.

It will get inserted and the remaining space will be padded with spaces

D.

None of the above

Answer: A

19. What does NUMBER (8, 2) in oracle mean?

A.

It means there are 8 digits in total, 6 digits before the decimal and

2 after the decimal

B.

It means there are 10 digits in total with 8 digits before the decimal and 2 after decimal

C.

It means there are 2 digits before the decimal and 8 after the decimal point

D.

None of the above

Answer: A.

20. Which of the following queries will create a table with

no rows in it?

A.

CREATE TABLE emp AS SELECT 0 from dual ;

B.

CREATE TABLE emp AS SELECT * from employees where 1 = 1 ;

C.

CREATE TABLE emp AS SELECT * from employees where 1 = 2 ;

D.

CREATE TABLE emp AS SELECT 0 from employees ;

Answer: C. The direct path operation CTAS (CREATE TABLE .. AS

SELECT..) can be used to copy the structure of an existing table without copying the data.

21. Which of the following are valid constraints in Oracle?

A.

INDEX

B.

GENERAL

C.

UNIQUE

D.

PRIMARY KEY

Answer: C, D. A NOT NULL constraint can be created only with the column-level approach. A PRIMARY KEY constraint doesn't allow duplicate or NULL values in the designated column. Only one

PRIMARY KEY constraint is allowed in a table. A FOREIGN KEY constraint requires that the column entry match a referenced column entry in the table or be NULL. A UNIQUE constraint is similar to a PRIMARY KEY constraint, except it allows storing NULL values in the specified column. A CHECK constraint ensures that data meets a given condition before it's added to the table.

22. Which of the below DML operations consider constraints

on a column?

A.

INSERT

B.

UNION

C.

DELETE

D.

UPDATE

Answer: A, C, D. All the DML operations obey constraints on the columns of the table.

23. When can a constraint be created?

A.

While creating a table

B.

After creating a table

C.

Both A and B

D.

None of the above

Answer: C. A constraint can be included during table creation as part of the CREATE TABLE command or added to an existing table with the ALTER TABLE command.

24. What is the functional difference between a column-

level constraint and a table-level constraint?

A.

Column-level constraint applies to all the columns of a table

B.

Table-level constraint applies to all the columns of a table

C.

They both are functionally the same, only the syntax is different

D.

None of the above

Answer: C. Functionally, the table level constraints and column level constraints work similar. Composite constraints can be defined at table level only.

25. What is true about column-level constraints?

A.

They can be created before the creation of a table

B.

They can be created before the defining of a column

C.

They are included when the column is defined

D.

None of the above

Answer: C. Column level constraints are defined along with the column specification.

26. What is true about NOT NULL constraints in SQL?

A.

They should be defined at the table level

B.

They should be defined at the column level

C.

They should be defined only on one column

D.

They should be defined only on one row

Answer: B. A NOT NULL constraint can be created only with the column-level approach.

Consider the following statement and answer the questions

27 and 28 that follow:

CREATE TABLE employees (

emp_id NUMBER ( 6 ) CONSTRAINT emp_emp_id_PK PRIMARY KEY , first_name VARCHAR2 ( 20 ), last_name VARCHAR2 ( 20 ), hire_date DATE

);

27.Which type of constraint is created in the above

statement?

A.

Column level constraint

B.

Table level constraint

C.

Named constraint

D.

Specification constraint

Answer: A. A column level constraint is created along with the column definition.

28. What modification can be made to the above statement

to give it a table level constraint?

A.

CONSTRAINT emp_emp_id_PK PRIMARY KEY

B.

CONSTRAINT emp_emp_id_PK PRIMARY KEY (EMP_ID)

C.

CONSTRAINT emp_emp_id_PK EMP_ID PRIMARY KEY

D.

CONSTRAINT PRIMARY KEY emp_emp_id_PK

Answer: B.

29. What is true about PRIMARY KEY constraint?

A.

It applies a NOT NULL constraint implicitly to the column on which it is defined

B.

It applies a UNIQUE KEY constraint implicitly to the column on which it is defined

C.

It applies a CHECK constraint implicitly to the column on which it is defined

D.

It applies a DEFAULT constraint implicitly to the column on which it is defined

Answer: A,B . A PRIMARY KEY constraint doesn't allow duplicate or NULL values in the designated column. Only one PRIMARY KEY constraint is allowed in a table.

30. What among the following is true regarding a UNIQUE

KEY constraint?

A.

UNIQUE KEY constraint and PRIMARY KEY constraint are the same

B.

UNIQUE KEY constraint allows NULL values if there is no NOT NULL defined on the column(s)

C.

We can have two identical rows when a UNIQUE KEY constraint is defined on a column

D.

None of the above

Answer: B. A UNIQUE constraint is similar to a PRIMARY KEY constraint, except it allows storing NULL values in the specified column.

Consider the following statement and answer the questions

31 and 32 that follow:

CREATE TABLE employees ( emp_id NUMBER ( 6 ) first_name VARCHAR2 ( 20 ), last_name VARCHAR2 ( 20 ), job VARCHAR2 ( 20 ), hire_date DATE

CONSTRAINT emp_job_UK UNIQUE ( job ));

31. Which of the below statements interpret the above

CREATE TABLE script?

A.

This table cannot have two identical Job IDs

B.

This table can have two or more identical Job IDs

C.

This table can have NULL values in the JOB column

D.

None of the above

Answer: A, C. A UNIQUE constraint on the JOB column will restrict duplicate value but allows nulls.

32. If the constraint emp_job_UK is modified as

emp_job_PK PRIMARY KEY (job), what will be outcome?

A.

This change can happen only if there's no NULL value in the JOB column

B.

This change can happen without any restrictions

C.

This change will change the values of the column JOB

D.

None of the above

Answer: A.

33. What is true about the UNIQUE key constraint?

A.

A unique key index is implicitly created when a UNIQUE constraint is defined on a column

B.

A PRIMARY KEY constraint is implicitly created when a UNIQUE constraint is defined on a column

C.

A NOT NULL constraint is implicitly created when a UNIQUE constraint is defined on a column

D.

None of the above

Answer: A. When a unique constraint is imposed on a table,

Oracle internally creates a unique key index on the column to restrict the duplication of values.

34.Which of the following CREATE TABLE statements is not

valid?

A.

CREATE TABLE EMPLOYEES

( emp_id NUMBER ( 2 ) PRIMARY KEY , first_name VARCHAR ( 20 ), last_name VARCHAR ( 20 ), hire_date DATE NOT NULL );

B.

CREATE TABLE EMPLOYEES

( emp_id NUMBER ( 2 ) PRIMARY KEY NOT NULL , first_name VARCHAR ( 20 ), last_name VARCHAR ( 20 ), hire_date DATE NOT NULL PRIMARY KEY );

C.

CREATE TABLE EMPLOYEES

( emp_id NUMBER ( 2 ) PRIMARY KEY , first_name VARCHAR ( 20 ), last_name VARCHAR ( 20 ), hire_date DATE NOT NULL UNIQUE );

D.

CREATE TABLE EMPLOYEES

( emp_id NUMBER ( 2 ), first_name VARCHAR ( 20 ), last_name VARCHAR ( 20 ), hire_date DATE NOT NULL ,

CONSTRAINT emp_emp_id_PK PRIMARY KEY ( emp_id ));

Answer: B

35. How many PRIMARY KEY constraints can a table have?

A.

0

B.

Unlimited

C.

2

D.

1

Answer: D. A table can have one and only one primary key.

36. Which of the following commands will help in converting

the foreign key values to NULL?

A.

ON DELETE CASCADE

B.

ON DELETE SET NULL

C.

CASCADE

D.

REFERENCES

Answer: B.

Consider the following query and answer the questions 37

to 39 that follow:

CREATE TABLE EMPLOYEES

( emp_id NUMBER ( 2 ), first_name VARCHAR ( 20 ), last_name VARCHAR ( 20 ), dept_id NUMBER ( 10 ), hire_date DATE DEFAULT SYSDATE

CONSTRAINT emp_emp_id_PK PRIMARY KEY ( emp_id , hire_date )

CONSTRAINT emp_dept_FK FOREIGN KEY ( dept_id )

REFERENCES departments ( dept_id )

);

37. Which of the below statements interpret the CREATE

TABLE script?

A.

A FOREIGN KEY constraint is defined at the table level on the column

DEPT_ID

B.

The FOREIGN KEY constraint defined references the DEPT_ID from the

DEPARTMENTS table

C.

Both A and B

D.

None of the above

Answer: C. The keywords FOREIGN KEY and REFERENCES are used when we define a FOREIGN KEY constraint for referential integrity.

38. You need to delete all the dependent rows in

DEPARTMENTS table when you delete the EMPLOYEES table.

Which of the following command will solve the purpose?

(Consider the table structures as given)

SQL > DESC employees

Name Null ?

Type

---------------------------------------------

EMPLOYEE_ID

FIRST_NAME

NOT NULL NUMBER ( 6 )

VARCHAR2 ( 20 )

LAST_NAME NOT NULL VARCHAR2 ( 25 )

EMAIL

PHONE_NUMBER

HIRE_DATE

JOB_ID

SALARY

COMMISSION_PCT

MANAGER_ID

DEPARTMENT_ID

NOT NULL VARCHAR2 ( 25 )

VARCHAR2 ( 20 )

NOT NULL DATE

NOT NULL VARCHAR2 ( 10 )

NUMBER ( 8 , 2 )

NUMBER ( 2 , 2 )

NUMBER

NUMBER

(

(

6

4

)

)

SQL > DESC departments

Name Null ?

Type

---------------------------------------------

DEPARTMENT_ID NOT NULL NUMBER ( 4 )

DEPARTMENT_NAME NOT NULL VARCHAR2 ( 30 )

MANAGER_ID NUMBER ( 6 )

LOCATION_ID NUMBER ( 4 )

A.

ON DELETE SET NULL

B.

ON DELETE CASCADE

C.

DELETE ALL

D.

FOR UPDATE

Answer: B. If ON DELETE CASCADE is included in the constraint definition and a record is deleted from the parent table, any corresponding records in the child table are also deleted automatically.

39. The EMPLOYEES table as shown below, has 5 employees who work in department 10. An executive from admin

department issues the below query.

DELETE FROM departments

WHERE dept_id = 10 ;

What will be the outcome of this query?

A.

Integrity constraint error

B.

Successful execution

C.

Neither of A nor B

D.

None of the above

Answer: A. The DEPT_ID from DEPARTMENTS is the foreign key in the table EMPLOYEES and there are employees in department 10

,hence a value cannot be deleted from the parent table unless the child record is found.

Consider the following statement and answer the questions

40 to 45 that follow:

CREATE SEQUENCE dept_deptid_seq

INCREMENT BY 100

START WITH 101

MAXVALUE 9999

NOCACHE

NOCYCLE ;

40.What will be the first value generated by this sequence?

A.

1

B.

100

C.

101

D.

9999

Answer: C. The START WITH clause establishes the starting value for the sequence. Oracle 11g begins each sequence at 1 unless another value is specified in the START WITH clause.

41.What can be the last value generated by this sequence?

A.

0

B.

100

C.

9901

D.

9999

Answer: C. The MINVALUE and MAXVALUE clauses establish a minimum or maximum value for the sequence.

42.What will be the 2nd value generated by this sequence?

A.

102

B.

201

C.

99

D.

9999

Answer: B. The INCREMENT BY clause specifies the interval between two sequential values. If the sequence is incremented by a positive value, the values the sequence generates are in ascending order. However, if a negative value is specified, the values the sequence generates are in descending order. If the

INCREMENT BY clause isn't included when the sequence is created, the default setting is used, which increases the sequence by one for each integer generated.

43.What will be the next value after the maximum integer

9999 is reached by this sequence?

A.

101

B.

No value

C.

It will throw an ORA error

D.

None of the above

Answer: B. The CYCLE and NOCYCLE options determine whether

Oracle 11g should begin reissuing values from the sequence after reaching the minimum or maximum value.

44.You execute the below query:

SELECT dept_depid_seq .

NEXTVAL from dual ;

Assuming that the last value the sequence generated was 200, what will be the outcome of this query?

A.

200

B.

101

C.

9999

D.

201

Answer: D. The NEXTVAL pseudocolumn will generate the next unique integer of the sequence.

45.You execute the below query:

SELECT dept_depid_seq .

CURRVAL from dual ;

Assuming that the last value the sequence generated was 200, what will be the outcome of this query?

A.

200

B.

101

C.

9999

D.

201

Answer: A. The CURRVAL pseudocolumn will generate the current unique integer already generated by the sequence.

Consider the CUSTOMERS table create by the following query:

CREATE TABLE CUSTOMERS

( id NUMBER ( 2 ),

Name VARCHAR2 ( 20 ), age NUMBER ( 10 ),

ADDRESS VARCHAR2 ( 20 ) NOT NULL, salary NUMBER (8, 2 ),

CONSTRAINT CUSTOMERS_id_PK PRIMARY KEY ( CUSTOMERS )

);

And consider the CUSTOMERS table having the following records:

+----+----------+-----+-----------+----------+

| ID | NAME | AGE | ADDRESS | SALARY |

+----+----------+-----+-----------+----------+

| 1 | Ramesh | 32 | Ahmedabad | 2000.00

|

| 2 | Khilan | 25 | Delhi | 1500.00

|

| 3 | kaushik | 23 | Kota | 2000.00

|

| 4 | Chaitali | 25 | Mumbai | 6500.00

|

| 5 | Hardik | 27 | Bhopal | 8500.00

|

| 6 | Komal | 22 | MP | 4500.00

|

| 7 | Muffy | 24 | Indore | 10000.00

|

+----+----------+-----+-----------+----------+

Which of the following statements true, and which is false:

Insert into CUSTOMERS

Values(3,'Ramy', 33,'Cairo',670.00);

Insert into CUSTOMERS

Values(13,'Amany', 33,NULL,670.00);

Insert into CUSTOMERS

Values(23,'Aly', 33,'Cairo',8888670.00);

Insert into CUSTOMERS

Values(33,NULL, 33,'Cairo',700.00);

Download