Use DML to perform data addition, deletion and modification

In the previous article, we learned how to create and maintain tables in the database. With the table, we can perform some data operations. Today we will learn how to add, delete, modify and merge the data in the table.

Increase data

SQL mainly provides two methods to increase data:

  1. INSERT INTO … VALUES … ;
  2. INSERT INTO … SELECT … ;

First, the syntax of the first form is as follows:

INSERT INTO t(col1, col2, ...)
VALUES (value1, value2, ...);

Among them, t is the table name; the value provided in the VALUES clause and the number of fields in the INSERT INTO must be the same, and the data types must be compatible.

for example:

-- 只有 Oracle 需要执行以下 alter 语句
-- alter session set nls_date_format = 'YYYY-MM-DD';
INSERT INTO employee(emp_id, emp_name, sex, dept_id, manager, hire_date, job_id, salary, bonus, email)
VALUES ( 26, '张三', '男', 5, 18, '2019-12-25', 10, 6000, NULL, '[email protected]');

The above statement adds an employee to the employee table. If the VALUES value list is exactly the same as the field order in the table, the field list can be omitted; the above example can also be abbreviated as:

-- 只有 Oracle 需要执行以下 alter 语句
-- alter session set nls_date_format &

Guess you like

Origin blog.csdn.net/horses/article/details/108729088