1. 程式人生 > >OCP-1Z0-051 第1題 CTAS語句建表注意事項

OCP-1Z0-051 第1題 CTAS語句建表注意事項

一、 原題
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


       


       答案  B

二、題目翻譯:
看下圖中SALES, CUSTOMERS, PRODUCTS, and TIMES這幾張表的結構,SALES表有一個外來鍵列PROD_ID,關聯到PRODUCTS表。類似地,CUST_ID and TIME_ID 列也是SALES表的外來鍵列,分別關聯到表CUSTOMERS和表TIMES,
下面的這條CREATE TABLE建表命令:
CREATE TABLE new_sales(prod_id, cust_id, order_date DEFAULT SYSDATE)
AS
SELECT prod_id, cust_id, time_id
FROM sales;
關於這個命令,下面哪一種說法是正確的:
A.NEW_SALES這張表不能建立成功,因為列定義時,不能指定預設值。
B.NEW_SALES這張表能建立成功,並且所有 指定列上的已定義的非空約束會帶到新表。
C.NEW_SALES表不能建立成功,因為CREATE TABLE命令中的列名與SELECT子句中的列名不匹配。
D.NEW_SALES表可以建立成功,並且所有指定列上的已定義的外來鍵約束會帶新表。


三、題目解析:

        使用CREATE TABLE..AS..語句建立表時,原表列上如果有顯式非空約束會傳遞給新表,其它約束都不會帶到新表。

      Oracle Database automatically defines on columns in the new table any NOT NULL constraints that have a state of NOT DEFERRABLE and VALIDATE, and were explicitly created on the corresponding columns of the selected table if the subquery selects the column rather than an expression containing the column. If any rows violate the constraint, then the database does not create the table and returns an error.
       顯式的NOT NULL約束自動會帶到新表。

      NOT NULL constraints that were implicitly created by Oracle Database on columns of the selected table (for example, for primary keys) are not carried over to the new table.
       隱式的NOT NULL約束不會帶到新表,如主鍵。

    In addition, primary keys, unique keys, foreign keys, check constraints, partitioning criteria, indexes, and column default values are not carried over to the new table.
       另外,主鍵,唯一,外來鍵,check約束,分割槽,索引以及列的預設值不會帶到新表。

       If the selected table is partitioned, then you can choose whether the new table will be partitioned the same way, partitioned differently, or not partitioned. Partitioning is not carried over to the new table. Specify any desired partitioning as part of the CREATE TABLE statement before the AS subquery clause.
     在新表上可以選擇是否像舊錶那樣分割槽,或者不同的分割槽形式,或者不分割槽的表,分割槽不會被帶到新表中, 在AS subquery句之前指定。


相關推薦

OCP-1Z0-051 1 CTAS語句注意事項

一、 原題 View the Exhibit and examine the structure of the SALES, CUSTOMERS, PRODUCTS, and TIMES tables.The PROD_ID column is the foreign ke

OCP-1Z0-051 64 order by使用別名注意事項

View the Exhibit and examine the data in the PROMO_CATEGORY and PROMO_COST columns of the PROMOTIONS table.         Evaluate the following two queries: SQ

OCP-1Z0-051 174 事務的組成

Which statement is true regarding transactions? (Choose all that apply.) A. A transaction can consist only of a set of DML and DDL statements.B. A part or

OCP-1Z0-051 51 SYNONYM同義詞

Which statement is true regarding synonyms? A. Synonyms can be created only for a table. B. Synonyms are used to reference only those tables that are owned

OCP-1Z0-051 54

View the Exhibit and examine the structure of the CUSTOMERS table. Evaluate the query statement: SQL> SELECT cust_last_name, cust_city, cust_credit_limi

OCP-1Z0-051 2 檢視的WITH CHECK OPTION選項

SQL>  CREATE VIEW v4  2  AS SELECT prod_id, cust_id, SUM(quantity_sold) FROM SALES  3  WHERE time_id <= SYSDATE - 2*365  4  GROUP BY prod_id, cust_id

OCP-1Z0-051 45 SEQUENCE(序列)的注意事項

Which two statements are true about sequences created in a single instance database? (Choose two.) A. The numbers generated by a sequence can be used only

OCP-1Z0-051 37 drop table

一、原題 You issued the following command to drop the PRODUCTS table: SQL> DROP TABLE products; What is the implication of this command? (

OCP-1Z0-051 43 序列的cycle選項

Evaluate the following CREATE SEQUENCE statement: CREATE SEQUENCE seq1 START WITH 100 INCREMENT BY 10 MAXVALUE 200 CYCLE NOCACHE; The SEQ1 sequence has gen

OCP-1Z0-051 62 where萬用字元

     EMPNO ENAME ---------- ----------       7876 ADAMS       7499 ALLEN       7698 BLAKE       7782 CLARK       7902 FORD       7900 JAMES       7566 JO

OCP-1Z0-051 172 事務savepoint的注意事項

The SQL statements executed in a user session are as follows:SQL> CREATE TABLE product                  (pcode NUMBER(2),                   pname VARCHA

OCP-1Z0-051 46 約束和索引

Which statements are correct regarding indexes? (Choose all that apply.)A. When a table is dropped, the corresponding indexes are automatically dropped.B.

OCP-1Z0-051 142 巢狀子查詢的應用

View the Exhibit and examine the structure of the PRODUCTS table. Evaluate the following query:SQL> SELECT prod_name        FROM products       WHERE pr

OCP-1Z0-051 131 LEFT OUTER JOIN和RIGHT OUTER JOIN的用法

View the Exhibit and examine the structure of the PRODUCT, COMPONENT, and PDT_COMP tables. In PRODUCT table, PDTNO is the primary key. In COMPONENT table,

OCP-1Z0-051 149 子查詢中ALL的應用

View the Exhibits and examine the structures of the COSTS and PROMOTIONS tables. Evaluate the following SQL statement:SQL>SELECT prod_id       FROM cost

OCP-1Z0-051 113 GROUP BY, TO_CHAR的應用

Examine the structure of the ORDERS table:Name                Null                Type ORDER_ID           NOT NULL           NUMBER(12) ORDER_DATE        

OCP-1Z0-051 52 列別名

View the Exhibit and examine the structure of the PRODUCTS table. Using the PRODUCTS table, you issue the following query to generate the names, current li

OCP-1Z0-051 47 索引

View the Exhibit and examine the structure of ORD and ORD_ITEMS tables. The ORD_NO column is PRIMARY KEY in the ORD table and the ORD_NO and ITEM_NO column

OCP-1Z0-051 140 子查詢中使用GROUP BY注意事項

Examine the structure of the PRODUCTS table:Name             Null             Type PROD_ID         NOT NULL        NUMBER(4) PROD_NAME                     

OCP-1Z0-051 130 LEFT OUTER JOIN的用法

View the Exhibit and examine the data in the EMPLOYEES table: You want to display all the employee names and their corresponding manager names. Evaluate th