您的位置:首页 > 其它

Chapter 09-Manipulating Data - 01

2013-04-16 22:54 351 查看

Objectives

After completing this lesson,you should be able to do the following:

Describe each data manipulation language(DML) statement.

Insert rows into a table.

Update rows in a table.

Delete rows from a table.

Control transactions.

Lesson Agenda

Adding new rows in a table

-INSERT statement

Changing data in a table

-UPDATE statement

Removing rows from a table:

-DELETE statement

-TRUNCATE statement

Database transactions control using COMMIT,ROLLBACK,and SAVEPOINT

Read consistency

FOR UPDATE clause in a SELECT statement

Data Manipulatioin Language

A DML statement is executed when you:

-Add new rows to a table

-Modify existing rows in a table

-Remove existing rows from a table

A transaction consists of a collection of DML statements that form a logical unit of work.

Adding a New Row to a table

very simple to do , you know

INSERT Statement Syntax

Add new rows to a table by using the INSERT statement

INSERT INTO table [(column,[,column...])]
VALUES (value [,value...]);


With this syntax,only one row is inserted at a time.

INSERT New Rows

Insert a new row containing values for each column.

List values in the default order of the columns in the table.

Optionally,list the columns in the INSERT clause.

INSERT INTO departments(department_id,department_name,manager_id,location_id)
VALUES(70,'Public Relations',100,1700);


Enclose character and date values within single quotation marks.

Build a Lab Environment

Copy Data From Another Table

SQL> INSERT INTO DEPT SELECT * FROM departments;

27 rows created.

SQL> SELECT * FROM DEPT;

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
10 Administration                        200        1700
20 Marketing                             201        1800
30 Purchasing                            114        1700
40 Human Resources                       203        2400
50 Shipping                              121        1500
60 IT                                    103        1400
70 Public Relations                      204        2700
80 Sales                                 145        2500
90 Executive                             100        1700
100 Finance                               108        1700
110 Accounting                            205        1700

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
120 Treasury                                         1700
130 Corporate Tax                                    1700
140 Control And Credit                               1700
150 Shareholder Services                             1700
160 Benefits                                         1700
170 Manufacturing                                    1700
180 Construction                                     1700
190 Contracting                                      1700
200 Operations                                       1700
210 IT Support                                       1700
220 NOC                                              1700

DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------
230 IT Helpdesk                                      1700
240 Government Sales                                 1700
250 Retail Sales                                     1700
260 Recruiting                                       1700
270 Payroll                                          1700

27 rows selected.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: