What is DMl?
Answer:
DML: Data Manipulation Language data manipulation language, with INSERT, UPDATE, and DELETE as the core instructions, respectively representing insert, update and delete, is a command that must be mastered.
Insert value
Method 1:
insert into demo1[(字段,字段,...,字段)] values(值,值,...,值)
Method 2:
insert into demo1 set 字段=值,字段=值,...,字段=值
Description:
One-to-one correspondence between values and fields
If it is a character or date type, the value needs to be enclosed in single quotes; if it is a numeric type, there is no need to use single quotes
The number of fields and values must be the same, the position corresponds
If the field cannot be empty, you must insert a value
Fields that can be empty can be inserted without value
The fields after the table name can be omitted and not written. At this time, all fields are shown in the same order as the fields in the table.
Insert values in bulk
Method 1:
insert into demo2[(字段,字段,...,字段)] values(值,值,...,值),(值,值,...,值),...,(值,值,...,值)
Method 2:
insert into demo2[(字段,字段,...,字段)] select语句
Single table update
update 表名 [[as] 别名] set [别名.]字段=值 [where 条件]
Multi-table update
update 表名1 [[as] 别名1],表名2 [[as] 别名2] set [别名1.]字段=值,set [别名2.]字段=值 [where条件]
It is recommended to use a single-table update to facilitate maintenance.
Single table delete (delete the data in the table)
delete [别名] from 表名 [[as] 别名]
note:
If an alias is used, the alias must be written after delete
If there is no alias, the table name is the alias or can be omitted without writing
Multi-table deletion (delete the data in the table)
delete [别名1][,[别名2] from 表名1 [[as] 别名1],表名2 [[as] 别名2] [where条件]
note:
When deleting multiple tables, there must be an alias between delete from. If there is no alias after from, the default alias is used, which is the table name.
truncate delete
truncate 表名
Delete all data in the table
The difference between drop, truncate and delete
truncate and drop are database definition languages (DDL)
delete is the database operation language (DML)
Judgment | drop | truncate | delete |
---|---|---|---|
Whether to support conditional deletion | not support | not support | stand by |
Whether to support table structure deletion | stand by | not support | not support |
Whether to support transaction delete | not support | not support | stand by |
Whether to trigger the trigger | no | no | Yes |