preface

This article mainly introduces the mysql data operation, some database basic add, delete, change, check, routine use method, a look.

Mysql > insert into mysql

  • Mysql operation 01 – Basic instructions, SQL library operations
  • Mysql > select * from ‘SQL’;
  • Mysql operation 03 – SQL data operation
  • Mysql > alter table SQL > alter table SQL > alter table SQL > alter table SQL > alter table SQL
  • Mysql Operations 05 – SQL advanced data operations

SQL data manipulation

The new data

There are two options

Scenario 1: Insert data into a full table field without specifying a field list

Requirements: The sequence of data values must be the same as that of the designed fields in the table. All non-numeric data must be wrapped in quotation marks (single quotation marks are recommended).

Basic syntax:

Insert into values(values)[, values]; -- Multiple data can be inserted at a timeCopy the code

Ex. :

Insert, insert data into my_student values (1, 'inst111', 'Jim,' male '), ((2, 'inst222', 'jsse', 'male');Copy the code

Scheme 2: Insert data into some fields, and select the field list. The order of the field list has nothing to do with the order of the fields. But the order of the list of values must be the same as the order of the selected fields.

Basic syntax:

Insert into values [, values]; insert into values [, values];Copy the code

Ex. :

Insert data: Insert into my_student (number,sex,name,id) values (' icTAST002 ','male',' Tom ',3), ('ictast002','male','lily',4);Copy the code

View the data

Basic syntax:

Select */ from table_name where table_name [select * from table_name];Copy the code

Ex. :

Select * from my_student; Select id,number,sex from my_student where id=1; -- View the data that satisfies id 1Copy the code

Update the data

Basic syntax:

Select * from table_name where table_name = 1; -- Recommend to have where, or update allCopy the code

Example: this article mainly introduces the mysql data operation, some basic add, delete, change, check, routine use methods, let’s have a look.

Update my_student set sex = 'female' where name = 'Jim ';Copy the code

Initial updates are not always successful, such as when there is no data to actually update. If the initial value of the data is 1 and the data is updated to 1, then the data is not really updated. To determine the data update success, you need to determine the number of affected rows.

Delete the data

Basic syntax:

Delete from table name [where condition];Copy the code

Ex. :

Delete from my_student where sex = 'male';Copy the code

Note: Delete irreversible, delete with caution.