OCP-1Z0-051-V9.02-1題

1. View the Exhibit and examine the structure of the SALES, CUSTOMERS, PRODUCTS, and TIMES

tables.

The PROD_ID column is the foreign key in the SALES table, which references the PRODUCTS table.

Similarly, the CUST_ID and TIME_ID columns are also foreign keys in the SALES table referencing the

CUSTOMERS and TIMES tables, respectively.

Evaluate the following CREATE TABLE command:

CREATE TABLE new_sales(prod_id, cust_id, order_date DEFAULT SYSDATE)

AS

SELECT prod_id, cust_id, time_id

FROM sales;

Which statement is true regarding the above command? 

 

A. The NEW_SALES table would not get created because the DEFAULT value cannot be specified in the

column definition.

B. The NEW_SALES table would get created and all the NOT NULL constraints defined on the specified

columns would be passed to the new table. 

C. The NEW_SALES table would not get created because the column names in the CREATE TABLE

command and the SELECT clause do not match. 

D. The NEW_SALES table would get created and all the FOREIGN KEY constraints defined on the

specified columns would be passed to the new table.

 

Answer: B

答案解析:

A答案:默認sysdate可以在列出被指定。

 

sh@TEST0924> CREATE TABLE new_sales(prod_id, cust_id, order_date DEFAULT SYSDATE) AS
  2  SELECT prod_id, cust_id, time_id FROM sales;
 
Table created.
 
B答案:NULL約束會傳遞。由以下可以看出,not null是可以傳遞的。B正確
第一種方法,查看錶的結構,可見not null約束是可以傳遞的。
sh@TEST0924> desc SALES
 Name                                                  Null?    Type
----------------------------------------------------- -------- ------------------------------------
 PROD_ID                                               NOT NULL NUMBER
 CUST_ID                                               NOT NULL NUMBER
 TIME_ID                                               NOT NULL DATE
 CHANNEL_ID                                       NOT NULL NUMBER
 PROMO_ID                                          NOT NULL NUMBER
 QUANTITY_SOLD                                NOT NULL NUMBER(10,2)
 AMOUNT_SOLD                                  NOT NULL NUMBER(10,2)
 
sh@TEST0924> desc new_sales
 Name                                                  Null?    Type
----------------------------------------------------- -------- ------------------------------------
 PROD_ID                                               NOT NULL NUMBER
 CUST_ID                                               NOT NULL NUMBER
 ORDER_DATE                                     NOT NULL DATE
第二種方法:由下面的查詢看出,not null也是傳遞的。B正確
sh@TEST0924> select a.owner,a.TABLE_NAME,b.COLUMN_NAME,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.SEARCH_CONDITION
  2  from USER_CONSTRAINTS a,USER_CONS_COLUMNS b
  3  where a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and A.table_name='SALES';
 
OWNER      TABLE_NAME COLUMN_NAME     CONSTRAINT_NAME                CONSTRAINT SEARCH_CONDITION
---------- ---------- --------------- ------------------------------ ---------- ------------------------------
SH         SALES      CUST_ID                    SALES_CUSTOMER_FK              R
SH         SALES      PROD_ID                  SALES_PRODUCT_FK               R
SH         SALES      TIME_ID                   SALES_TIME_FK                          R
SH         SALES      CHANNEL_ID          SALES_CHANNEL_FK               R
SH         SALES      PROD_ID                  SYS_C0011009                           C                  "PROD_ID" IS NOT NULL
SH         SALES      CUST_ID                   SYS_C0011010                           C                  "CUST_ID" IS NOT NULL
SH         SALES      TIME_ID                  SYS_C0011011                           C                  "TIME_ID" IS NOT NULL
SH         SALES      CHANNEL_ID          SYS_C0011012                       C              "CHANNEL_ID" IS NOT NULL
SH         SALES      PROMO_ID              SYS_C0011013                       C              "PROMO_ID" IS NOT NULL
SH         SALES      QUANTITY_SOLD   SYS_C0011014                       C          "QUANTITY_SOLD" IS NOT NULL
SH         SALES      AMOUNT_SOLD     SYS_C0011015                       C          "AMOUNT_SOLD" IS NOT NULL
SH         SALES      PROMO_ID            SALES_PROMO_FK                 R
 
12 rows selected.
 
sh@TEST0924> l
  1   select a.owner,a.TABLE_NAME,b.COLUMN_NAME,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.SEARCH_CONDITION
  2  from USER_CONSTRAINTS a,USER_CONS_COLUMNS b
  3*  where a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and A.table_name='NEW_SALES'
sh@TEST0924> /
 
OWNER      TABLE_NAME COLUMN_NAME     CONSTRAINT_NAME                CONSTRAINT SEARCH_CONDITION
---------- ---------- --------------- ------------------------------ ---------- ------------------------------
SH         NEW_SALES  PROD_ID         SYS_C0011428                   C          "PROD_ID" IS NOT NULL
SH         NEW_SALES  CUST_ID         SYS_C0011429                   C          "CUST_ID" IS NOT NULL
SH         NEW_SALES  ORDER_DATE      SYS_C0011430                   C          "ORDER_DATE" IS NOT NULL
 
C答案:
由A中所見,此表是可以創建的,雖然字段名不一樣,但數據庫類型一樣,就可以創建表。C錯誤。
D答案:
由B第二種方法看出,僅僅只是傳遞了not null約束,而SALES_PRODUCT_FK,SALES_CUSTOMER_FK,SALES_TIME_FK這三個外鍵約束是沒有被傳遞的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章