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
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 .
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
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
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
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
If I want to query the data whose id is less than 3, then we can write like this
select * from admin where id
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
After performing the deletion operation, we You can check the data in the table
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!