MySQL's DML language (additions and deletions)

MySQL's DML language (additions and deletions)

Supplement, foreign keys: Do not use foreign keys, all foreign key concept in the application layer to solve.

Add that the database column, is the field name, try to bring the symbol `Gone with the Wind

Existing database significance: data storage and data management.

Database: line (Data), a column (field)

Note: This page is to solve the problem of data lines . Previous columns are fields to solve the problem.

Language DML: Data Manipulation Language

1, add (insert)

2, update (update)

3, delete (delete)

1. Add insert (add data to the line in)

- insert statement (add) 
- form: INSERT INTO `` table name (field name `1`,` 2` field names, field names `3`) VALUES ( 'value 1', 'value 2', 'value 3 '), (' value 1 ',' value 2 ',' value 3 '), (' value 1 ',' value 2 ',' value 3 ')
the INSERT the INTO student` `(` name`, `age` , `sex`) the VALUES ( 'Xiaoming', '22 is', 'man'), ( 'Xiaohong', '20 is', 'Woman'), ( 'Xiaoli', '25', 'man')

note:

1, show and field names above the symbol is: `Gone with the Wind

2, the value of the above symbols are: single quotes'

2. Modify update

2.1 judgment statement symbol

Operators meaning range result
= equal 5=6 false
<> Or! = not equal to 5<>6 true
> more than the    
< Less than    
<= Less than or equal    
>= greater or equal to    
BETWEEN ... ADN ... Within a certain range (closed loop) [2,5]  
AND And 5<1 ADN 1>2 false
OR or 5>1 OR 1>2 true

2.2 modify the value of a field, unconditional

- change, unconditionally. Format: UPDATE `table name field name` `` the SET value = 
the UPDATE `student` the SET` name` = 'Beihang'   - effect name field for all values are Beihang

2.3 modify a value of the field specified condition

- change, conditional. Format: UPDATE `table name field name` `` the SET value = value of the WHERE id = 1 OR id = value 2 
the UPDATE `student` the SET` name` = 'Dongda' the WHERE id = . 1 OR = id . 3   - Effect all id value at 1 name field and 3 are DongDa

2.4 plurality modified value of the field specified condition

- change, conditional. Format: UPDATE `` the SET table name `1` field name = 'value 1', 2 '' field name = 'value 2' WHERE field name 1 AND BETWEEN numerical value of 2 
the UPDATE` student` the SET `name` = 'Beihang' , `sex` = 'man' the WHERE Age the BETWEEN 20 is the AND 25   - effect all age name in the range of 20 to 25 becomes BeiHang, sex becomes man

3. Delete (delete command or truncate command)

3.1 Method 1: delete command to delete all the data and specify the data table

The DELETE the FROM `student`;              - the effect is to completely remove the student table 
the DELETE the FROM` student` the WHERE ID = . 1;   - the effect is to specify the data in the student table deleted

3.2 Method 2: truncate table command to delete all the data

`Student` TRUNCATE;              - the effect is to completely remove the student table

3.3 distinguish two commands to delete all the data in the table

After Delete to delete, and then further added to the table data, auto-incremented id, it will sort down before continuing;

After truncate delete, auto-incremented id will not be sorted down.

Therefore, the hope when you delete all the data in the table, it is recommended to use TRUNCATE .

 

 

Guess you like

Origin www.cnblogs.com/WZ-BeiHang/p/12370002.html