Home  >  Article  >  Database  >  Commonly used basic operation syntax of mysql (3)~~ Add, delete and modify data [command line mode]

Commonly used basic operation syntax of mysql (3)~~ Add, delete and modify data [command line mode]

黄舟
黄舟Original
2017-03-03 13:57:181331browse

1. Insert a single piece of data: insert into tablename (field name 1, field name 2,...) values ​​(value 1, value 2,...);


As can be seen from the figure, every field does not need to have a value when inserting (provided there are no relevant constraints), but it should be noted that the number of fields and the number of subsequent values ​​must be consistent. The order and type of the custom fields must also be consistent, otherwise an error will be reported. In addition, if no fields are specified, all fields are selected by default. Each field must have a corresponding value, and the order must be consistent with the fields in the table, otherwise an error will be reported, as shown in the figure:



2. Insert multiple pieces of data: insert into tablename (field 1, field 2) values ​​(field 1 value, field 2 value) value),(field 1 value, field 2 value),(field 1 value, field 2 value)...;


##3. Insert query results: insert into tablename1 (field 1, field 2) select (field 1, field 2) from tablename2;


You can also add query conditions at the end:


## 4. Modify and update the data: update tablename set field name 1 = value 1, field name 2 = value 2...; if no conditions are added later, all

## will be updated.


# You can also add conditions later to update the data that meets the conditions:

5 , Delete data (record): delete from tablename where ...;

You can also not specify the conditions, so that all data will be deleted. In actual use, it may Just clear the data and use it. Normally, conditions will be added:

The above is the common basic operation syntax of mysql (3)~~Add, delete and modify operations on data [ Command line mode] content, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn