mysql study notes (2) _DML (Data Manipulation Language)

## DML (Data Manipulation Language) data manipulation language

  • Insert data: insert
  • Modify the data: update
  • Delete the data: delete
     

## DML (Data Manipulation Language) data manipulation language

############
#### insert statement
############
/ *
One way:
Syntax:
    INSERT INTO table name (column names ...) values ( value ...)
   Note: the column must not be null insert data, can be inserted as null null column, you can not write this column
* /
the SELECT * from t_student;
# 1 insert a data in the student table.
iNSERT iNTO t_student (name, age, score) values ( 'Keven', 19,66);

# 2 order of columns may be switched
insert into t_student (score, name, age) values (93, 'Semi', 17);

# 3 if the column name is omitted, the default is all columns
insert into t_student values (26, ' Hellen', 17,87, null);

# 4 can be inserted into a plurality of data
insert into t_student (name, age, score) values ( 'Voli', 17,76), ( 'Wuje', 19,64);

/ *
Second way:
Syntax:
    INSERT INTO table name
    set name = value column, column name = value, ...

* /
# 1 to insert a table in the student data.
INSERT INTO t_student
set name = 'SANZI', =. 17 Age , score = 81;

/ *
    Way a support insert more than one row, second approach does not support the
    way a child can support queries, do not support the second approach

*/


## DML (Data Manipulation Language) data manipulation language

############
#### modification statements
############
/ *
    record table 1. amendments
    syntax: Update table
               set value = column, column = value, ...
               the WHERE filter criteria

    2. modify the record of multi-table [understand]
    syntax:
    SQL99 syntax:
            Update table 1 alias
            inner | left | right join aliases in table 2
            on the connection conditions
            set column = value, ...
            the WHERE screening condition

# 1 . Review student id = 29 data
Update t_student 
SET name = 'Kulen', Age = 18 is, Score = 82
WHERE id = 29;


## DML (Data Manipulation Language) data manipulation language
############
#### deleted the statement
############

/ *
Syntax:
    Method 1:
    Delete single table
        delete from the table where the filter criteria
    delete multiple tables [understand]
        sql92 syntax:
            Alias delete Table 1, Table 2 alias
            from Table 1 alias Table 2 alias
            where the join condition
            and filtering conditions

            
        sql99 syntax:
            alias delete table 1, table 2 alias
            from table 1 alias 
            inner | left | right join in table 2 aliases
            on the join condition
            where the filter conditions

    Second way:
        TRUNCATE the table table (delete all the data in the table, not added the WHERE)
    
* /
. # 1 student information deleted id = 16
delete from t_student where id = 26;

# 2 Delete player's team id = 1 is
the DELETE T the FROM P t_player
        the INNER the JOIN
    t_team T = the ON p.tid t.id 
the WHERE
    p.id = 1;

# 3 Delete id = 1 and the player's team the player
the DELETE T P the FROM P t_player
        the INNER the JOIN
    t_team T = the ON p.tid t.id 
the WHERE
    p.id = 1;

# 4 Clear rangdom Table
truncate table random;
 

Published 60 original articles · won praise 10 · views 9176

Guess you like

Origin blog.csdn.net/chaseqrr/article/details/104486655