使用DDL语句问题

1. Oracle DB中DDL的完整形式是什么?

  1. 数据删除语言

  2. 数据定义语言

  3. 数据委派语言

  4. 虚拟数据语言

答案:B. DDL是SQL的一个类别,代表数据定义语言.其他SQL类型是DML,DCL和TCL.

2.DDL语句用于以下哪个Oracle数据库对象?

  1. 表格

  2. 子查询

答案:A. DDL包含CREATE,ALTER和ANALYZE等命令用于CREATE TABLE,查看存储的子程序和数据库模式中的包.

3. Oracle数据库中包含数据的基本存储单元是什么?

  1. 查看

  2. 栏目

  3. 查询

答案:D.表格基本Oracle数据库中数据的物理存储单元.

4.以下哪个选项最能定义视图?

  1. 它是表格的缩写形式

  2. 它是来自一个或多个表的子集的逻辑表示

  3. 它只有一行一列

  4. 以上都不是

答案:B. View是一个查询,其行为类似于格式化一个或多个表中包含的数据的窗口.视图不包含任何物理数据,只包含在运行时创建的查询.

5.以下哪些是数据库对象?

  1. 序列

  2. 同义词

  3. 以上所有

答案:D.物理存储在数据库模式中的对象是数据库对象.

6.以下哪个数据库对象生成数值?

  1. 查看

  2. 索引

  3. 序列

答案:D.序列用于生成以确定值开始并以指定因子递增的唯一值.可以创建序列以生成一系列整数.序列生成的值可以存储在任何表中.使用CREATE SEQUENCE命令创建序列.

7.以下哪些数据库对象为对象提供了替代名称?

  1. 同义词

  2. 序列

  3. 查看

  4. 索引

答案:A.同义词为数据库对象提供永久别名.任何数据库用户都可以使用公共同义词.私有同义词仅适用于创建它的用户.使用CREATE SYNONYM命令创建同义词.使用DROP SYNONYM命令删除同义词.只有具有DBA权限的用户才能删除公共同义词.

8.以下哪些数据库对象可以提高某些查询的性能?

  1. 同义词

  2. 查看

  3. 索引

答案:D.

9.什么时候可以创建表?

  1. 当数据库没有被任何用户使用时

  2. 新创建数据库时

  3. 即使用户使用数据库,也可以随时创建

  4. 以上都不是

答案:C.可以创建索引以加快查询过程.当索引存在时,DML操作总是较慢. Oracle 11g自动为PRIMARY KEY和UNIQUE约束创建索引.使用CREATE INDEX命令创建显式索引.如果查询条件或排序操作基于用于创建索引的列或表达式,则Oracle 11g可以自动使用索引.

10.关于表的真实情况是什么?

  1. 指定表的大小不是强制性的

  2. 每个表的大小相同

  3. 可以在线修改表格

  4. 没有上面

答案:A,C.

11.创建名为123_A的表,用于存储组织中的员工数.表的名称有什么问题?

  1. 表的名称不能以一个数字

  2. 此名称没有错.

  3. 在命名表时不能使用下划线

  4. 以上都不是

答案:A.根据对象命名约定,表名必须以字母开头.

12.表名可以包含的字母数量范围是多少?

  1. 1-20个字符

  2. 1-10个字符

  3. 1-30个字符

  4. 1-50个字符

答案:C.表名不能超过30个字符.

13可以使用以下哪个字符来命名表格?

  1. A到Z

  2. a到z

  3. 0到9

  4. 以上所有

答案:D.根据Oracle中的标准命名约定,对象的名称在任何情况下都可以包含字母表.强制性地,第一个地方是字母,其余的可以是字母和数字的混合.

14.可以使用以下哪些特殊字符来命名表格?

  1. @

  2. $

  3. _(下划线)

答案:B,C,D.在命名表时,除了(#,$,_)之外,不允许使用其他特殊字符.不鼓励在表名中使用特殊字符.

15.表的名称是什么?

  1. 一个表的名称可以是由同一用户拥有的其他对象使用

  2. 序列和表可以具有相同的名称

  3. 视图和表可以具有相同的名称名称

  4. 表名不得复制同一用户拥有的另一个对象的名称

答案:D.凭借命名空间,表名不能与任何其他模式对象相同.共享相同名称空间的模式对象包括表,视图,序列,私有同义词,存储过程,存储函数,包,物化视图和用户定义类型.

16.您创建一个表并将其命名为COUNT. CREATE TABLE脚本的结果是什么?

  1. 不会创建表格

  2. 该表格将被创建,下划线将自动添加到名称COUNT _

  3. 将抛出ORA错误

  4. 将创建COUNT表而不会出现任何错误

答案:A,C.您无法创建表格该名称与Oracle Server保留字相同.

17.您使用带引号的标识符''创建表.您将如何参考此表?

  1. 'table_name'

  2. "table_name"

  3. A或B
    中的任何一个

  4. 以上均不是

答案:B.如果使用带引号标识符的名称创建表,则必须对其进行处理使用双引号.建议不要使用带引号的标识符.带引号的标识符区分大小写

18.您创建一个名为EMPLOYEES的表.以下哪项是可能的?

  1. 它可以被称为eMPLOYEES

  2. 它可以被称为EMPLoyees

  3. 它可以被称为员工

  4. 以上所有

答案:D.在Oracle中,未加引号的对象名称不区分大小写.

19.以下是创建表的先决条件?

  1. CREATE TABLE权限

  2. 存储空间

  3. 表格中的数据

  4. 以上都不是

答案:A,B.用户必须拥有CREATE TABLE权限,并且必须有足够的空间将初始范围分配给表格段.

20.创建表的语法是什么?

  1. CREATE TABLE [schema.] table(column数据类型[DEFAULT expr] [,..]);

  2. CREATE TABLE INTO [schema.] table(列数据类型[DEFAULT expr] [,..]);

  3. CREATE TABLE VALUES [schema.] table(列数据类型[DEFAULT expr] [,..]);

  4. 以上都不是

答案:A.

21.选择创建表时必须指定的元素.

  1. 列名

  2. 列数据类型

  3. 列大小

  4. 以上所有

答案:D.一个表必须有一列atleasr,它的数据类型规范和精度(如果需要).

22.名为"Kevin"的用户想要访问另一个名为"Jonathan"的用户所拥有的表.以下哪项适用于Kevin?

  1. 从Kevin.employees中选择*;

  2. 从jonathan.employees中选择*;

  3. A或B中的任何一个

  4. 以上都不是

答案:B.

23.模式的真实情况是什么?

  1. 模式由数据库用户拥有并具有与该用户同名

  2. 每个用户拥有一个架构

  3. 架构对象包括数据库链接

  4. 全部上述

答案:D.数据库中的用户空间称为架构.模式包含用户拥有或访问的对象.每个用户可以拥有自己的单一模式.

24.关于表格,以下哪些是正确的?

  1. 给表的默认值

  2. 在INSERT语句期间可以为表的一列提供默认值

  3. A或B中的任何一个

  4. 以上都不是

答案:B.在定义期间,可以为列指定默认值关键字DEFAULT.

25.创建表时,以下哪项可以与DEFAULT选项一起使用?

  1. 字符串

  2. 表达式

  3. SQL函数

  4. 以上所有

答案:D.列的默认值可以是文字或使用SQL函数的派生.

26.以下哪个命令用于查看表的结构?

  1. UPDATE

  2. SHOW

  3. DESCRIBE

  4. SPOOL

答案:C. DESCRIBE是一个SQL * Plus命令,用于列出表格的结构.

27.What是列的CHECK约束的限制?

  1. 无限制

  2. 1

  3. 2

  4. 4

答案:答: Oracle对列的检查约束没有限制.

28.以下哪些命令会丢弃表员工? (考虑给定的表结构)

SQL> DESC employees
 Name			 Null?	  Type
 ----------------------- -------- ----------------
 EMPLOYEE_ID		 NOT NULL NUMBER(6)
 FIRST_NAME			  VARCHAR2(20)
 LAST_NAME		 NOT NULL VARCHAR2(25)
 EMAIL			 NOT NULL VARCHAR2(25)
 PHONE_NUMBER			  VARCHAR2(20)
 HIRE_DATE		 NOT NULL DATE
 JOB_ID 		 NOT NULL VARCHAR2(10)
 SALARY 			  NUMBER(8,2)
 COMMISSION_PCT 		  NUMBER(2,2)
 MANAGER_ID			  NUMBER(6)
 DEPARTMENT_ID			  NUMBER(4)

  1.  DROP员工

  2.  DROP TABLE员工

  3.  TRUNCATE员工

  4. 以上都不是

答案:B.

29.命名空间的真实情况是什么?

  1. 它是一组对象类型

  2. 在命名空间内,所有对象名称都应唯一标识模式和名称编辑

  3. 不同名称空间中相同类型的对象可以共享相同的名称

  4. 以上所有

答案:D.命名空间定义了一组对象类型,其中所有名称必须唯一标识 - 由schema和name.Objects in different名称空间可以共享相同的名称.

30.以下哪种对象类型共享同一名称空间?

  1. 同义词

  2. 观看次数

  3. 以上所有

答案:D.

31.关于表和索引,以下哪些是正确的?

  1. 索引和一个表在模式中可以具有相同的名称

  2. 模式中的索引和表不能具有相同的名称

  3. A和B都不是

  4. 以上都不是

答案:A.作为索引和构建aints共享相同的命名空间,表和索引可以具有相同的名称.

32.创建表的真实情况是什么?

  1. 创建表时,应为每列分配数据类型

  2. 数据类型赋值列不是必需的

  3. 必须将数据类型分配给表而不是列.

  4. 以上都不是

答案:A.为了构建表的结构,每列必须具有数据类型和精度等行为属性.

33.假设您创建了一个如下所示的表:

 CREATE TABLE employees 
 (emp_id NUMBER(4),
 last_name VARCHAR2(20)
);

Oracle分配给LAST_NAME列的空间是多少?

  1. 如果没有行,那么Oracle将不会为last_name列分配任何空间

  2. 如果填充了行,那么Oracle将分配无限空间last_name列

  3. 既不是A也不是B

  4. 以上都不是选项

答案:A.

34.尺寸范围是多少VARCHAR2数据类型可以采用?

  1. 1字节到2字节

  2. 1字节到2000字节

  3. 1字节到4000字节

  4. 以上都不是

答案:C.在Oracle 11g第2版之前,字符串数据类型VARCHAR2最多可包含4000个字节.

35. CHAR数据类型可以采用的大小范围是什么?

  1. 1字节到2字节

  2. 1个字节到2000字节

  3. 1字节到4000字节

  4. 1字节到3000字节

答案:B.在Oracle 11g第2版之前,字符串数据类型CHAR最多可包含2000个字节.

36.真实情况CHAR数据类型?

  1. 如果数据不是列的长度,那么它将被替换为NULL值

  2. 如果数据不是列的长度,那么它将用空格填充

  3. 强制要求拥有与CHAR大小相同大小的数据,否则会引发ORA错误

  4. 以上都不是

答案:B. CHAR为值提供固定长度的存储,而VARCHAR2是灵活的.如果长度小于CHAR精度的数据插入CHAR列,则剩余长度将填充到列值.

37.以下哪项是可变长度二进制数据的数据类型?

  1. VARCHAR

  2. VARCHAR2

  3. RAW

  4. NVARCHAR2

答案:C.

38.允许的精度是多少对于NUMBER数据类型?

  1. 1到20

  2. 1到4K

  3. 1到30

  4. 1到38位数

答案:D.在Oracle 11g第2版之前,主数据类型NUMBER的最大精确度为38位.

39.什么是NUMBER数据类型允许的比例?

  1. 1到20

  2. -84到100

  3. -84到127

  4. 没有以上

答案:C.

40 .以下哪项是日期和时间数据的数据类型?

  1. TIMESTAMP

  2. INTERVAL DAY TO SECOND

  3. TIMESTAMP WITH LOCAL TIMEZONE

  4. 以上所有

答案:D.

41.以下哪种数据类型适用于大型对象?

  1. CLOB

  2. BLOB

  3. RAW

  4. 以上所有

答案:A,B. SQL中的LOB数据类型是BLOB,CLOB和BFILE.

42.如果插入的值是为VARCHAR2数据类型列定义的较小长度会发生什么?

  1. 它会抛出一个ORA错误

  2. 它会成功插入,并且该值将占用所需的空间.

  3. 它将被插入并且剩余空间将用空格填充

  4. 以上都不是

答案:B. VARCHAR2包含可变长度字符数据.

43. oracle中的NUMBER(8,2)是什么意思?

  1. 这意味着总共有8位数字,小数点前6位数字和小数点后2位数字

  2. 这意味着总共有10位数字小数点前8位数字和小数点后2位数

  3. 表示小数点前有2位数,小数点后8位数

  4. 没有以上

答案:A. p表示精确度,左右两边的总位数小数位,最多38位; s或scale表示十进制右边的位置数.例如:NUMBER(7,2)可以存储最大为99999.99的数值.如果未指定precision或scale,则列默认精度为38位.

44.以下哪个查询将创建一个没有行的表?

  1.  CREATE TABLE emp AS SELECT 0 from dual;

  2.  CREATE TABLE emp AS SELECT *来自员工,其中1 = 1;

  3.  CREATE TABLE emp AS SELECT *来自员工,其中1 = 2;

  4.  CREATE TABLE emp AS SELECT 0来自员工;

答案:C.直接路径操作CTAS(CREATE TABLE .. AS SELECT ..)可用于复制现有表的结构而不复制数据.

45.以下哪个语句会为已创建的表添加列?

  1.  ALTER TABLE table_name add column(job varchar2(20));

  2.  ALTER TABLE table_name add job varchar2( 20);

  3.  ALTER TABLE table_name add(job varchar2(20));

  4.  ALTER TABLE table_name add column(job);

答案:C. ALTER TABLE命令允许用户向表中添加新列.在新表中创建列的相同规则适用于向现有列添加列table.新列必须由列名和数据类型(以及宽度,如果适用)定义.还可以分配默认值.区别在于新列添加在现有表的末尾 - 它将是最后一列.

46.以下哪个语句将修改数据类型已存在的列?

  1.  ALTER TABLE table_name修改(作业varchar2(10));

  2.  ALTER TABLE table_name MODIFY job varchar2(10);

  3.  ALTER TABLE table_name MODIFY列(作业varchar2(10));

  4.  ALTER TABLE table_name MODIFY(job varchar2(10));

答案:A. ALTER TABLE..MODIFY用于修改表中的列定义.可接受的更改是增加列精度,更改数据类型系列中的数据类型,或更改列的默认值.

47.以下哪个语句将从中删除列表?

  1.  ALTER TABLE table_name DROP(job varchar2(10));

  2.  ALTER TABLE table table_name DROP COLUMN(job varchar2(10));

  3.  ALTER TABLE table table_name DROP COLUMN(job);

  4.  ALTER TABLE table_name MODIFY(job varchar2(10));

答案:C. ALTER TABLE..DROP COLUMN可用于从表中删除一列.

48.以下哪一项将重命名列emp_id到empno?

  1.  ALTE R TABLE员工RENAME列emp_id到empno;

  2.  ALTER TABLE员工RENAME emp_id到empno;

  3.  ALTER TABLE员工RENAME列emp_id到empno;

  4. 没有以上;

答案:A. ALTER TABLE..RENAME可用于重命名表中的现有列.

49.您需要将表员工标记为只读.您将执行以下哪项陈述来获得所需的结果?

  1.  ALTER TABLE员工设置READ;

  2.  ALTER TABLE员工只读;

  3.  ALTER TABLE员工READ_ONLY;

  4.  ALTER TABLE员工设置READ ONLY;

答案:B.表格可以被标记为只读以使其对DML和DDL语句被动. Oracle 11g中引入了只读功能.

50.以下关于DDL语句的内容是什么?

  1. DDL命令成为正在进行的事务的一部分

  2. DDL命令是自动提交并结束正在进行的活动事务

  3. 如果DDL命令失败,则仍然提交当前事务

  4. 如果DDL命令失败,则回滚当前事务

答案:B. DDL命令只有在成功执行且没有错误的情况下才会自动提交.如果DDL命令失败,则正在进行的事务仍在会话中处于活动状态,并且未提交到数据库中.

51.如果存在针对表的活动事务,会发生什么情况发行DDL?

  1. 交易回滚

  2. 交易已提交并终止

  3. A和B

  4. 以上都不是

答案:B.

52.以下哪个命令会删除SQL语句中未使用的列?

  1.  ALTER TABLE tablename DROP COLUMN column_name;

  2.  ALTER TABLE tablename DROP未使用的列;

  3.  ALTER TABLE tablename设置未使用的列;

  4.  ALTER TABLE tablename DROP columns;

答案:C. SET UNUSED命令只删除表中未使用的列并且更快

53.当尝试删除标记为只读的表时会发生什么?

  1. 会抛出错误

  2. 它将不再保持只读但不能被删除

  3. 它将被删除而没有错误

  4. 它将保持不被触摸

答案:C. DROP命令会影响表格的数据字典定义不是只读的,因此可以删除

考虑以下语句并回答以下问题54和55:

 CREATE TABLE部门
(dept_id NUMBER(2),
 dept_name VARCHAR2(14),
 create_date DATE DEFAULT SYSDATE);

54.如果从语句中删除DEFAULT子句规范会发生什么?

  1. 脚本将抛出错误,因为DATE列必须使用默认值指定

  2. 系统生成的默认值将分配给列

  3. 表格将创建为no CREATE_DATE列的默认值

  4. 以上都不是

答案:C.

55.上述陈述有什么用?

  1. 会在会话中自动提交事务

  2. 它将在架构中创建表DEPARTMENTS

  3. 它将设置默认值CREATE_DATE列的值

  4. 以上都不是

答案:A,B,C./b>

56. BLOB数据类型列的值可以保持多少?

  1. 1 KB

  2. 2 GB

  3. 4 GB

  4. 3 KB

答案:C.根据Oracle 11g,BLOB中容纳的最大数据大小可以是4GB.

57. CLOB和BLOB数据类型有什么区别? (选择最合适的答案)

  1. CLOB是字符数据,BLOB是二进制数据

  2. CLOB是高达2GB的字符数据,BLOB是高达4 GB的二进制数据

  3. CLOB是高达4 GB的字符数据,BLOB是二进制数据到4 GB

  4. 以上都不是

答案:C. CLOB是一个字符大对象,用于存储PDF,docs和文本文件等字符文件,而BLOB是用于存储媒体文件的二进制LOB.

58.以下是什么是一个ROWID?

  1. 这是一个以1开头的行的序列号

  2. 这是一个给表中一行的字母数字地址

  3. A和B

  4. 无以上

答案:B.它是一个base-64系统,表示其表中行的唯一地址.

59.用于存储二进制数据的数据类型是什么存储在外部文件中(最多4 GB)?

  1. BLOB

  2. CLOB

  3. CFILE

  4. BFILE

答案:D. BFILE是一种外部LOB类型,用于引用外部媒体文件.内部LOB类型是BLOB和CLOB,用于存储在数据库中的二进制大文件和字符大文件.

60.使用子查询创建的表有什么用?

  1. VARCHAR2数据类型列使用子查询创建表时不复制

  2. 使用子查询创建表时不复制CLOB数据类型列

  3. 使用子查询创建表格时不会复制LONG列

  4. 以上都不是

答案:C.创建表格的CTAS方法不会复制LONG列.

61.以下哪种数据类型不能与GROUP BY和ORDER BY子句一起使用?

  1. CLOB

  2. VARCHAR2

  3. CHAR

  4. LONG

答案:D.在GROUP BY和ORDER BY子句中不能使用LONG数据类型.

62.表中包含多少个LONG列?

  1. 最高2

  2. 最低2

  3. 只有一个

答案:D.一个表最多可以包含一列LONG类型.

63.以下哪种数据类型不能在SQL中约束?

  1. VARCHAR2

  2. LONG

  3. CHAR

  4. DATE

答案:B.无法在LONG类型列上创建约束.

64. Which of the following data types can you use if you want a date with fractional seconds?

  1. DATE

  2. VARCHAR2

  3. TIMESTAMP

  4. None of the above

Answer: C. The TIMESTAMP data type provides additional precised information of date values. It provides fractional seconds and time zone information.

65. You need to store an interval of days, hours, minutes and seconds in a column. Which of the data type would help?

  1. TIMESTAMP

  2. INTERVAL YEAR TO MONTH

  3. INTERVAL DAY TO SECOND

  4. None of the above

Answer: C.

66.You need to find how many employees were hired in June, 2011 and June, 2012. Which of the following data types will help?

  1. INTERVAL DAY TO SECOND

  2. TIMESTAMP

  3. DATE

  4. INTERVAL YEAR TO MONTH

Answer: D.

67. What is true about constraints?

  1. They enforce rules at the row level

  2. They enforce rules at the table level

  3. It is mandatory to have constraints created while creating a table

  4. None of the above

Answer: B. A constraint is a rule applied to data being added to a table. It represents business rules, policies, or procedures.Data violating the constraint isn’t added to the table.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. A constraint based on composite columns (more than one column) must be created by using the table-level approach.

68. How are constraints helpful?

  1. They limit the storage capacity of a table and hence save DB space

  2. They prevent the modification of a table

  3. They prevent deletion of a table if there are dependencies

  4. None of the above

Answer: C. A constraint is a rule applied to data being added to a table.It represents business rules, policies, or procedures.Data violating the constraint isn’t added to the table.

69.A RAW data type column can store variable-length binary strings up to what value?

  1. 10 GB

  2. 1 TB

  3. 2 GB

  4. 4 GB

Answer: C.

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

  1. INDEX

  2. GENERAL

  3. UNIQUE

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

71. Which of the below DML operations consider constraints on a column?

  1. INSERT

  2. UNION

  3. DELETE

  4. UPDATE

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

72. When can a constraint be created?

  1. While creating a table

  2. After creating a table

  3. Both A and B

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

73 Where are constraints stored?

  1. In the SGA

  2. In a table

  3. In data dictionary

  4. None of the above

Answer: C.

74. You create a constraint but do not name it. What will be the default name given to the constraint?

  1. SYS_Cn

  2. SYS_constraint

  3. SYS_Const

  4. SYS_C0

Answer: A. By default, Oracle gives a generic name to the constraints SYS_Cn, where the n is an integer to keep the name of a constraint unique.

75. What is the functional difference between a column-level constraint and a table-level constraint?

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

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

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

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

76. What is true about column-level constraints?

  1. They can be created before the creation of a table

  2. They can be created before the defining of a column

  3. They are included when the column is defined

  4. None of the above

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

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

  1. They should be defined at the table level

  2. They should be defined at the column level

  3. They should be defined only on one column

  4. 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 78 and 79 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  
 );

78.Which type of constraint is created in the above statement?

  1. Column level constraint

  2. Table level constraint

  3. Named constraint

  4. Specification constraint

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

79. What modification can be made to the above statement to give it a table level constraint?

  1. CONSTRAINT emp_emp_id_PK PRIMARY KEY

  2. CONSTRAINT emp_emp_id_PK PRIMARY KEY (EMP_ID)

  3. CONSTRAINT emp_emp_id_PK EMP_ID PRIMARY KEY

  4. CONSTRAINT PRIMARY KEY emp_emp_id_PK

Answer: B.

80. What is true about PRIMARY KEY constraint?

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

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

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

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

Answer: A. 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.

81. What among the following is true regarding a UNIQUE KEY constraint?

  1. UNIQUE KEY constraint and PRIMARY KEY constraint are the same

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

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

  4. 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 82 and 83 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));

82. Which of the below statements interpret the above CREATE TABLE script?

  1. This table cannot have two identical Job IDs

  2. This table can have two or more identical Job IDs

  3. This table can have NULL values in the JOB column

  4. None of the above

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

83. If the constraint emp_job_UK is modified as emp_job_PK PRIMARY KEY (job), what will be outcome?

  1. This change can happen only if there’s no NULL value in the JOB column

  2. This change can happen without any restrictions

  3. This change will change the values of the column JOB

  4. None of the above

Answer: A.

84. What is true about the UNIQUE key constraint?

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

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

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

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

85. Which of the following is true about indexes?

  1. If an UPDATE statement is executed on a table, the indexes need to be manually updated as well

  2. If a DELETE statement is executed on a table, the indexes need to manually deleted as well

  3. When a table is dropped, the indexes are automatically dropped

  4. If an UPDATE statement is executed on a table, the corresponding indexes are updated as well.

Answer: C, D.

86.Which of the following CREATE TABLE statements is valid?

  1. CREATE TABLE EMPLOYEES  
     (emp_id NUMBER (2) PRIMARY KEY, 
     first_name VARCHAR(20), 
     last_name VARCHAR(20), 
     hire_date DATE NOT NULL);
  2. 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);
  3. CREATE TABLE EMPLOYEES  
     (emp_id NUMBER (2) PRIMARY KEY, 
     first_name VARCHAR(20), 
     last_name VARCHAR(20), 
     hire_date DATE NOT NULL UNIQUE);
  4. 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: A, C, D. All the CREATE TABLE scripts are valid.

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

  1. 0

  2. Unlimited

  3. 2

  4. 1

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

88. You want to put a CHECK constraint on the EMP_ID such that it should be equal to the current value of a Sequence through which it is getting its values. Which of the following statements will help you achieve this?

  1. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (emp_id = EMPNO.CURRVAL);

  2. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (emp_id = EMPNO.NEXTVAL);

  3. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (EMPNO.CURRVAL);

  4. None of the above

Answer: D. You cannot use CURRVAL, NEXTVAL, LEVEL and ROWNUM pseudo columns in the CHECK constraint

89. Which of the following commands will help in converting the foreign key values to NULL?

  1. ON DELETE CASCADE

  2. ON DELETE SET NULL

  3. CASCADE

  4. REFERENCES

Answer: B.

90. You need to add a constraint to the EMPLOYEES table which restricts the addition of those employees who have salaries less than 10000. Which of the following commands will give you the required results?

  1. ALTER TABLE employees ADD CONSTRAINT emp_emp_sal_CHECK CHECK (salary>= 10000);
  2. ALTER TABLE employees ADD CHECK CONSTRAINT emp_emp_sal_CHECK (salary>10000);
  3. ALTER TABLE employees ADD CONSTRAINT CHECK emp_emp_sal_CHECK (salary = 10000);
  4. ALTER TABLE employees ADD CONSTRAINT emp_emp_sal_CHECK (salary<10000);

Answer: A.

91. You need to add a constraint to the EMPLOYEES table which imposes a restriction that the HIRE_DATE for all the employees should be equal to SYSDATE-7. Which of the following statements will give you the required results?

  1. ALTER TABLE employees ADD CHECK CONSTRAINT emp_emp_sal_CHECK  ( to_char(hire_date,’DD-MON-YY’) = SYSDATE -7);
  2. ALTER TABLE employees ADD CONSTRAINT CHECK emp_emp_sal_CHECK ( to_char(hire_date,’DD-MON-YY’) = SYSDATE -7);
  3. ALTER TABLE employees ADD emp_emp_sal_CHECK CHECK ( to_char(hire_date,’DD-MON-YY’) = SYSDATE -7);
  4. None of the above

Answer: D. You cannot use SYSDATE, UID, USER and USERENV functions in the CHECK constraint.

Consider the following query and answer the questions 92 to 94 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) 
 );

92. Which of the below statements interpret the CREATE TABLE script?

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

  2. The FOREIGN KEY constraint defined references the DEPT_ID from the DEPARTMENTS table

  3. Both A and B

  4. None of the above

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

93. 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		 NOT NULL NUMBER(6)
 FIRST_NAME			  VARCHAR2(20)
 LAST_NAME		 NOT NULL VARCHAR2(25)
 EMAIL			 NOT NULL VARCHAR2(25)
 PHONE_NUMBER			  VARCHAR2(20)
 HIRE_DATE		 NOT NULL DATE
 JOB_ID 		 NOT NULL VARCHAR2(10)
 SALARY 			  NUMBER(8,2)
 COMMISSION_PCT 		  NUMBER(2,2)
 MANAGER_ID			  NUMBER(6)
 DEPARTMENT_ID			  NUMBER(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)

  1. ON DELETE SET NULL

  2. ON DELETE CASCADE

  3. DELETE ALL

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

94. 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? (Assume the table structures as shown)

SQL> DESC employees
 Name			 Null?	  Type
 ----------------------- -------- ----------------
 EMPLOYEE_ID		 NOT NULL NUMBER(6)
 FIRST_NAME			  VARCHAR2(20)
 LAST_NAME		 NOT NULL VARCHAR2(25)
 EMAIL			 NOT NULL VARCHAR2(25)
 PHONE_NUMBER			  VARCHAR2(20)
 HIRE_DATE		 NOT NULL DATE
 JOB_ID 		 NOT NULL VARCHAR2(10)
 SALARY 			  NUMBER(8,2)
 COMMISSION_PCT 		  NUMBER(2,2)
 MANAGER_ID			  NUMBER(6)
 DEPARTMENT_ID			  NUMBER(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)

  1. Integrity constraint error

  2. Successful execution

  3. Neither of A nor B

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