Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic operating tutorial of SQL data in MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is mainly to bring you MySQL SQL data basic operation tutorial, I hope these contents can bring you practical use, this is also the main purpose of my editing MySQL SQL data basic operation tutorial this article. Okay, no more nonsense, let's go straight to the following.

SQL Basic Operations

Basic operation: CURD, i.e., add, delete and check.

According to the different operation objects, we can divide the basic operations of SQL into three categories: library operations, table (field) operations and data operations.

data operation

1 New data

There are two ways to add data.

Type 1: Insert data into a full table field without specifying a list of fields, but requires that the order in which the values of the data appear must be consistent with the order in which the fields appear in the table, and that all non-numeric data be enclosed in quotes (single quotes are recommended).

Basic syntax: insert into + table name + values(list of values)[,(list of values)];

Example: insert into test values ('charies ', 18,' 3.1');

Type 2: To insert data into some fields, you need to select a field list. The order in which the fields appear in the field list has nothing to do with the order of the fields in the table, but the order of the field values in the value list must be consistent with the order in the field list.

Basic syntax: insert into + table name (field list) + values(value list)[,(value list)];

insert into test(age,name) values(18,'guo');

2 Query data

View all-> Basic syntax: select * from + table name + [where condition];

Select * from test;

View section-> Basic syntax: select + field name [, field name] + from + table name + [where condition];

Example: select name,age,grade from test where age = '18';

3 Updated data

Basic syntax: update + table name + set + field = value + [where condition];

Example: update test set age = 20 where name = 'guo';

Here, it is recommended to add the where condition as much as possible, otherwise, the operation is the full table data.

In addition, judging whether the update operation is successful does not depend on whether the SQL statement is executed successfully, but on whether there are records affected, that is, when the number of affected is greater than 1, the update is truly successful.

4 Delete data

Basic syntax: delete from + table name + [where condition];

Example: delete from test where grade = '3.1';

Of course, we can also use drop to achieve deletion, but compared with delete, drop is more powerful, when it performs deletion operation, it will not only delete data, but also delete definitions and free storage space; while delete when performing deletion operation, it will only delete data, and will not delete definitions and free storage space.

Warm tip: content enclosed by symbol [] indicates optional; symbol + indicates connection.

For the above tutorial on SQL data basic operations in MySQL, do you think it is very helpful? If you need to know more, please continue to pay attention to our industry information, I believe you will like these contents.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report