SQL1-ch8 操作資料 (DML) 1. 題號  80 題: 47 、 67  140 題: 12 、 49 、 50 、 55 、 79 、 80 、 89 、 111 2.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

SQL2-ch1 控制使用者存取. 題號  80 題: 14 、 22 、 40 、 42 、 52  140 題: 9 、 40 、 103.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Virtual training week 4 structured query language (SQL)
SQL1-ch2 限制和排序資料. 考古題題號  80 題: 27 、 51  140 題: 23 、 58 、 70.
9-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language A DML statement is executed when you: – Add new rows to a table.
SQL Review Sections 1 - SQL and other basic statements.
SQL1-ch11 使用資料說明視觀表 (Data Dictionary) 管理物件. 題號  80 題: 6 、 64  140 題: 105.
Last modified 2004/02 An Introduction to SQL (Structured Query Language )
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows in a table Delete rows from a table.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
DEFAULT Values and the MERGE Statement. 2 home back first prev next last What Will I Learn? Understand when to specify a DEFAULT value. Construct and.
Lecture 2: Using DDL Statements to Create and Manage Tables & Indexes
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Manipulating Data in PL/SQL. 2 home back first prev next last What Will I Learn? Construct and execute PL/SQL statements that manipulate data with DML.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
SQL Server 2005 使用與管理 建國科技大學 資管系 饒瑞佶. SQL Server Management Studio.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Database Programming Sections 7 & 8 – Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
SQL1-ch5 顯示多個表格的資料. 題號  80 題: 34 、 57 、 71 、 72  140 題: 18 、 25 、 62 、 97 、 115 、 131.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
SQL1-ch10 其他綱要物件. 題號  80 題: 5 、 9 、 18 、 32 、 38 、 41 、 44 、 54 、 77  140 題: 76 、 78 、 120 、 132.
Manipulating Data. Objectives After completing this lesson, you should be able to do the following: Describe each DML statement Insert rows into a table.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
9 Manipulating Data. 9-2 Objectives At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows.
SQL1-ch1 使用SQL SELECT 敘述句擷取資料.
SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127.
Database Programming Sections 7–Multi-row sub queries, IN, ANY, ALL, Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE,
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Copyright © 2004, Oracle. All rights reserved. Lecture 2: Using DDL Statements to Create and Manage Tables & Indexes ORACLE.
DML Part 1 Yogiek Indra Kurniawan. All Files Can Be Downloaded at : Menu : “Perkuliahan”
SQL2-ch4 群組相關資料以產生報表. 題號  80 題: 11 、 20 、 43 、 59 、 70 、 80  140 題: 14 、 88 、 113.
SQL1-ch4 群組函數與聚總資料. 題號  80 題: 33 、 39  140 題: 10 、 59 、 95 、 110.
Database Programming Sections 7– Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
SQL1-ch9 使用 DDL 建立與管理表格 1. 題號  80 題: 63 、 76  140 題: 6 、 24 、 44 、 71 、 77 、 92 2.
ORACLE SQL Fundamental II xpp-e-f 重點 xpp-e : Generating Reports by Grouping Related Data xpp-f : Hierarchical Retrieval.
4 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Using Data Model Editor to Create Data Models Based on a SQL Query Data Set.
Copyright © 2004, Oracle. All rights reserved. M ANIPULATING D ATA.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
1 Introduction to Database Systems, CS420 SQL JOIN, Group-by and Sub-query Clauses.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Database Programming Sections 7 & 8 – Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Manipulating Data.
“Manipulating Data” Lecture 6.
مقدمة في قواعد البيانات
“Manipulating Data” Lecture 6.
Manipulating Data.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
SQL2-ch3 操控大型資料集.
DATABASE ADMINISTRATION
Presentation transcript:

SQL1-ch8 操作資料 (DML) 1

題號  80 題: 47 、 67  140 題: 12 、 49 、 50 、 55 、 79 、 80 、 89 、 111 2

SQL 種類  資料操作 DML(Data Manipulation Language)  插入、修改、刪除資料列  資料定義 DDL(Data Definition Language)  建立、更改、刪除表格  資料控制 DCL(Data Control Language)  Commit 、 Rollback 、 Grant 、 Revoke 3

DML-Insert 4  插入資料列 (Insert)  空值可用 NULL 或 ’’ 表示

Q67/80 View the Exhibit and examine the structure of the ORDERS table. The columns ORDER_MODE and ORDER_TOTAL have the default values 'direct' and 0 respectively. Which two INSERT statements are valid? (Choose two.) 5

A. INSERT INTO orders VALUES (1, '09-mar-2007', 'online','',1000); B. INSERT INTO orders (order_id,order_date,order_mode, customer_id,order_total) VALUES(1,TO_DATE(NULL), 'online', 101, NULL); C. INSERT INTO (SELECT order_id,order_date,customer_id FROM orders) VALUES (1,'09-mar-2007', 101); D. INSERT INTO orders VALUES (1,'09-mar-2007', DEFAULT, 101, DEFAULT); E. INSERT INTO orders (order_id,order_date,order_mode,order_total) VALUES (1,'10-mar-2007','online',1000); ORDER_IDORDER_DATEORDER_MODECUSTOMER_IDORDER_TOTAL NOT NULL DIRECT0 6

DML-Update  修改資料列 (Update)  設定空值可用「 Set 欄位 = null 」 7

DML-Delete  刪除資料列 (Delete) 8

資料庫交易  交易開始:第一個 DML 執行時  交易結束:  發出 commit 或 rollback 指令 (DCL)  執行 DDL 指令  結束 iSQL*Plus  系統當機 9

資料庫交易  Commit 後 SavePoint 會被清除 10

Q47/80 Given below are the SQL statements executed in a user session: CREATE TABLE product (pcode NUMBER(2), pname VARCHAR2(10)); INSERT INTO product VALUES(1, 'pen'); INSERT INTO product VALUES (2,'pencil'); SAVEPOINT a; UPDATE product SET pcode = 10 WHERE pcode = 1; SAVEPOINT b; DELETE FROM product WHERE pcode = 2; COMMIT; DELETE FROM product WHERE pcode=10; ROLLBACK TO SAVEPOINT a; Which statement describes the consequences? 11

A. No SQL statement would be rolled back. B. Both the DELETE statements would be rolled back. C. Only the second DELETE statement would be rolled back. D. Both the DELETE statements and the UPDATE statement would be rolled back. 12

Q111/140 You executed the following SQL statements in the given order: CREATE TABLE orders (order_id NUMBER(3) PRIMARY KEY, order_date DATE, customer_id number(3)); INSERT INTO orders VALUES (100,'10-mar-2007', 222); ALTER TABLE orders MODIFY order_date NOT NULL; UPDATE orders SET customer_id=333; DELETE FROM order; The DELETE statement results in the following error: ERROR at line 1: ORA-00942: table or view does not exist What would be the outcome? 13

A. All the statements before the DELETE statement would be rolled back. B. All the statements before the DELETE statement would be implicitly committed within the session. C. All the statements up to the ALTER TABLE statement would be committed and the outcome of UPDATE statement would be rolled back. D. All the statements up to the ALTER TABLE statement would be committed and the outcome of the UPDATE statement is retained uncommitted within the session. 14

Q49/140( 可略 ) View the Exhibit and examine the structure of the ORDERS table. Which UPDATE statement is valid? A.UPDATE orders SET order_date = '12-mar-2007', order_total IS NULL WHERE order_id = 2455; B.UPDATE orders SET order_date = '12-mar-2007', order_total = NULL WHERE order_id = 2455; C.UPDATE orders SET order_date = '12-mar-2007' AND order_total = TO_NUMBER(NULL) WHERE order_id = 2455; D.UPDATE orders SET order_date = TO_DATE('12-mar- 2007','dd-mon-yyyy'), SET order_total = TO_NUMBER(NULL) WHERE order_id = 2455; 15

Q79/140( 可略 ) View the Exhibit and examine the data in EMPLOYEES and DEPARTMENTS tables. In the EMPLOYEES table EMPLOYEE_ID is the PRIMARY KEY and DEPARTMENT_ID is the FOREIGN KEY. In the DEPARTMENTS table DEPARTMENT_ID is the PRIMARY KEY. Evaluate the following UPDATE statement: UPDATE employees a SET department_id = (SELECT department_id FROM departments WHERE location_id = '2100'), (salary, commission_pct) = (SELECT 1.1*AVG(salary), 1.5*AVG(commission_pct) FROM employees b WHERE a.department_id = b.department_id) WHERE first_name||' '||last_name = 'Amit Banda'; What would be the outcome of the above statement? 16

A. It would execute successfully and update the relevant data. B. It would not execute successfully because there is no LOCATION_ID 2100 in the DEPARTMENTS table. C. It would not execute successfully because the condition specified with the concatenation operator is not valid. D. It would not execute successfully because multiple columns (SALARY,COMMISSION_PCT)cannot be used in an UPDATE statement. 17

Q89/140( 可略 ) View the Exhibit and examine the structure of EMPLOYEES and JOB_HISTORY tables. The EMPLOYEES table maintains the most recent information regarding salary, department, and job for all the employees. The JOB_HISTORY table maintains the record for all the job changes for the employees. You want to delete all the records from the JOB_HISTORY table that are repeated in the EMPLOYEES table. Which two SQL statements can you execute to accomplish the task? (Choose two.) 18

A. DELETE FROM job_history j WHERE employee_id = (SELECT employee_id FROM employees e WHERE j.employee_id = e.employee_id) AND job_id = (SELECT job_id FROM employees e WHERE j.job_id = e.job_id); B. DELETE FROM job_history j WHERE (employee_id, job_id) = ALL (SELECT employee_id, job_id FROM employees e WHERE j.employee_id = e.employee_id ) C. DELETE FROM job_history j WHERE employee_id = (SELECT employee_id FROM employees e WHERE j.employee_id = e.employee_id AND j.job_id = e.job_id ) D. DELETE FROM job_history j WHERE (employee_id, job_id) = (SELECT employee_id, job_id FROM employees e WHERE j.employee_id = e.employee_id AND j.job_id = e.job_id ) 19

Q50/140 Which three statements indicate the end of a transaction? (Choose three.) A.after a COMMIT is issued B.after a ROLLBACK is issued C.after a SAVEPOINT is issued D.after a SELECT statement is issued E.after a CREATE statement is issued 20

Q80/140 View the Exhibit and examine the structure of ORDER_ITEMS and ORDERS tables. You need to remove from the ORDER_ITEMS table those rows that have an order status of 0 or 1 in the ORDERS table. Which two DELETE statements are valid? (Choose two.) 21

A. DELETE FROM order_items WHERE order_id IN (SELECT order_id FROM orders WHERE order_status in (0,1)); B. DELETE * FROM order_items WHERE order_id IN (SELECT order_id FROM orders WHERE order_status IN (0,1)); C. DELETE FROM order_items i WHERE order_id = (SELECT order_id FROM orders o WHERE i.order_id = o.order_id AND order_status IN (0,1)); D. DELETE FROM (SELECT * FROM order_items i,orders o WHERE i.order_id = o.order_id AND order_status IN (0,1)); 22

Q55/140 View the Exhibit and examine the descriptions of the DEPT and LOCATIONS tables. You want to update the CITY column of the DEPT table for all the rows with the corresponding value in the CITY column of the LOCATIONS table for each department. Which SQL statement would you execute to accomplish the task? 23

A. UPDATE dept d SET city = ANY (SELECT city FROM locations l); B. UPDATE dept d SET city = (SELECT city FROM locations l) WHERE d.location_id =l.location_id; C. UPDATE dept d SET city = (SELECT city FROM locations l WHERE d.location_id =l.location_id); D. UPDATE dept d SET city = ALL (SELECT city FROM locations l WHERE d.location_id = l.location_id); 24

Q12/140  View the Exhibit and examine the structure of ORDERS and CUSTOMERS tables. Which INSERT statement should be used to add a row into the ORDERS table for the customer whose CUST_LAST_NAME is Roberts and CREDIT_LIMIT is 600? Assume there exists only one row with CUST_LAST_NAME as Roberts and CREDIT_LIMIT as

A. INSERT INTO orders VALUES (1,'10-mar-2007', 'direct', (SELECT customer_id FROM customers WHERE cust_last_name='Roberts' AND credit_limit=600), 1000); B. INSERT INTO orders (order_id,order_date,order_mode, (SELECT customer_id FROM customers WHERE cust_last_name='Roberts' AND credit_limit=600),order_total) VALUES (1,'10-mar-2007', 'direct', &customer_id, 1000); C. INSERT INTO orders (order_id,order_date,order_mode, (SELECT customer_id FROM customers WHERE cust_last_name='Roberts' AND credit_limit=600),order_total) VALUES(1,'10-mar-2007', 'direct', customer_id, 1000); D. INSERT INTO (SELECT o.order_id, o.order_date,o.order_mode, c.customer_id, o.order_total FROM orders o, customers c WHERE o.customer_id = c.customer_id AND c.cust_last_name='Roberts' AND c.credit_limit=600 ) VALUES (1,'10-mar-2007', 'direct', (SELECT customer_id FROM customers WHERE cust_last_name='Roberts' AND credit_limit=600), 1000); ORDER_IDORDER_DATEORDER_MODECUSTOMER_IDORDER_TOTAL NOT NULL DIRECT0 26