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)ASSELECT prod_id, cust_id, time_idFROM sales;
Which statement is true regarding the above command?
題目翻譯:查看並檢查銷售、客戶、產品、日期表的結構。PROD_ID是銷售表參考產品表的外鍵,同樣的,CUST_ID和TIME_ID也是銷售表的外鍵,分別參照了客戶表和日期表,評估下面建立表的語句,CREATE……,哪一個表述是正確的?
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 specifiedcolumns 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:不能建立表,原因是不能在定義欄位指定預設值 (錯誤,我們可以再建立表的同時,通過Default指定相關欄位的預設值)
B: 可以建立表,NOT NULL約束也可以傳遞到新表中 (正確,可以通過desc NEW_SALES 查看新表的結構)
C: 不能建立表,因為建立表的欄位名和被選中表的欄位名不一樣 (錯誤,只要是對應欄位的資料類型一致就可以了,欄位名可以不一樣)
D:可以建立表,並且所有的外鍵約束也會傳遞到新表中 (錯誤,通過desc NEW_SALES可以發現只有非空約束傳遞到了新表)