Data Manipulation Language DML

1. What is a data manipulation language

    Data manipulation language DML (Data Manipulation Language) , through which users can realize basic operations on data. 

2. Three forms of data manipulation language:

      1) Insert: insert

      2) Modify: update

      3) Delete: delete

    2.1 Insert statement

          2.1.1 Method One of Inserting Statements: Classic Insertion

                   Syntax format: 

                                  insert into table name (column name 1,...) values ​​(value 1,...);

                  2.1.1.1 Features of classic insert statements:

                   ① The type of the inserted value must be consistent or compatible with the type of the column

                   ②The column that cannot be null must insert a value, and it can be null

                   ③The order of the columns can be exchanged, but the values ​​must be exchanged with the order of the columns

                   ④The number of columns and the number of values ​​must be consistent

                   2.1.1.3 Case : Add an employee's information to the employee table (id 111, name Zhang San, gender male, phone 19888888)

                  insert into employees(employee_id,employee_name,employee_sex,employee_phone) values('111','张三','男','19888888');

            2.1.2 The second way of inserting a statement:

                      Syntax format:

                                     insert into table name set column name 1 = value 1, column name 2 = value 2...;

                   2.1.2.1 Case:  Add an employee's information to the employee table (id 111, name Zhang San, gender male, phone 19888888)

                   insert into employees set employee_id=111,employee_name='张三',employee_sex='男',employee_phone='19888888';

            2.1.3 The difference between the two methods

                        ① Method one supports inserting multiple rows, and method two does not support

                        ② Method one supports sub-queries, and method two does not support sub-queries

    2.2 Modify the statement

          2.2.1 Modify the syntax format of the statement      

                sql92 syntax:
                 update table 1 alias, table 2 alias set column = value where connection condition and filter condition;

                sql99 syntax:
                update table 1 alias inner|left|right join table 2 alias on connection condition set column=value where filter condition;

          2.2.2 Classification of modify statements: modify single-table records and modify multi-table records

                   2.2.2.1 Deletion of a single table

                               Method 1: delete can delete the entire row or the entire table

                               Syntax format: delete from table name [where filter condition limit number of entries]

                               Method 2: truncate delete the entire table (empty data)

                               Syntax format: truncate table table name;

                  2.2.2.2 Deletion of multiple tables

                               sql92:

                                         delete the alias of table 1, the alias of table 2

                                         from table 1 alias, table 2 alias

                                         where join condition

                                         and filter

                               sql99:

                                         delete the alias of table 1, the alias of table 2

                                         from Table 1 alias

                                         inner|left|right join Table 2 alias on join conditions

                                         where filter conditions

           2.2.3 The difference between the two single table deletions

                    ① delete can add where condition, truncate can not add

                    ② Truncate deletes more efficiently

                    ③ Add the table to be deleted by the self-growth long column. If you use delete to delete and then insert the data, the value of the self-growth column starts from the breakpoint; after truncate is deleted, the value of the self-growth column in the inserted data starts from 1.

                    ④ truncate deletes without return value, delete deletes with return value (number of rows affected)

                    ⑤ truncate delete can not be rolled back, delete delete can be rolled back.

Recommended

      Recommended browser: Google Chrome

      Recommended Java environment: IDEA (IntelliJ IDEA)

          Recommended study this week: the study and application of JDBC

          Recommended learning video link: https://www.bilibili.com/video/BV1eJ411c7rf?from=search&seid=2172690829084319707

          Recommended practice Java environment: https://leetcode-cn.com/

Guess you like

Origin blog.csdn.net/weixin_52011642/article/details/111826366