Home > Database > Mysql Tutorial > body text

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

迷茫
Release: 2017-04-07 14:47:43
Original
8498 people have browsed it

In phpMyAdmin, when we click sql, we can write complete sql statements to perform table operations, such as querying, adding, modifying, and deleting data tables, which is what we often call add, delete, modify, and query. .

1. SQL statement to add data table

Use sql statement to insert data, Here we need to use insert into

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

There is no data in the admin table. Let’s write a sql statement to add a piece of data to the table

INSERT INTO `admin`(`id`, `name`, `pwd`) VALUES (1,'admin','123456')

Then execute, if an error is reported, then we have not added it .

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

In this way we have completed adding a piece of data. Now let’s go to the table to see if the data we just added exists

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

You can see that the data we just added exists in the table

2. SQL statement to modify the data table

Use sql statement to modify the data. We need to use the update statement. It should be noted that we are now using SQL statements to make modifications, so conditional modifications are required. For example, there are 5 pieces of information in my database table. If there are no conditions for modification, which piece should be modified? So we need to take this into consideration.

We just added a piece of information, and then I added several pieces of information to the data table

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

We now need to modify the third piece of information, So how to write sql statement?

UPDATE `admin` SET `name`='admin',`pwd`= '55555' WHERE id=3

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

In this way we will change the information of the data with id equal to 3

3. Query the information in the data table

Now we have to query the data table All the information in the table, then when we write the sql statement, we can write

select * from admin

. In this way, we can query the information in the table. Of course We can also query with conditions. There are 4 pieces of data in our admin table. I only want to query the data whose id is 1. At this time we have to write conditions

select * from admin where id =1

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

If I want to query the data whose id is less than 3, then we can write like this

select * from admin where id

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

In this way, all ids less than 3 are queried.

4. SQL statement to delete the data table

To delete the information in the data table, we need to use delete. We want to delete the id of 4 in the data table. Data

delete from `admin` where id=4

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

After performing the deletion operation, we You can check the data in the table

Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial)

In this way, the data with id 4 in the table has been deleted.

The above is the detailed content of Tutorial on adding, deleting, modifying and querying data tables using SQL statements (phpMyAdmin usage tutorial). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!