zoukankan      html  css  js  c++  java
  • 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这三个外键约束是没有被传递的。

     

     

  • 相关阅读:
    【校招面试 之 C/C++】第23题 C++ STL(五)之Set
    Cannot create an instance of OLE DB provider “OraOLEDB.Oracle” for linked server "xxxxxxx".
    Redhat Linux安装JDK 1.7
    ORA-10635: Invalid segment or tablespace type
    Symantec Backup Exec 2012 Agent for Linux 卸载
    Symantec Backup Exec 2012 Agent For Linux安装
    You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5 SP1
    YourSQLDba介绍
    PL/SQL重新编译包无反应
    MS SQL 监控数据/日志文件增长
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317144.html
Copyright © 2011-2022 走看看