Home >Database >Mysql Tutorial >How to add, delete, modify and query mysql

How to add, delete, modify and query mysql

下次还敢
下次还敢Original
2024-04-22 19:42:32463browse

Perform CRUD in MySQL: Insert (CREATE): Use the INSERT INTO statement to insert data into the table. Delete (DELETE): Use the DELETE FROM statement to delete data from the table based on conditions. Update (UPDATE): Use the UPDATE statement to update data in the table based on conditions. Query (SELECT): Use the SELECT statement to select data from a table based on conditions.

How to add, delete, modify and query mysql

How to add, delete, modify and query in MySQL

MySQL is a popular relational database management system. Provides CRUD operations on data.

INSERT (CREATE)

To insert data into a MySQL table, you can use the INSERT INTO statement. The syntax is as follows:

<code class="sql">INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...)</code>

For example, to insert data into the users table:

<code class="sql">INSERT INTO users (name, email, age) VALUES ('John Doe', 'john.doe@example.com', 30)</code>

DELETE

To delete from MySQL To delete data from the table, you can use the DELETE FROM statement. The syntax is as follows:

<code class="sql">DELETE FROM table_name WHERE condition</code>

For example, to delete a specific user from the users table:

<code class="sql">DELETE FROM users WHERE id = 1</code>

Update (UPDATE)

To update data in a MySQL table, you can use the UPDATE statement. The syntax is as follows:

<code class="sql">UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition</code>

For example, update the age of the user in the users table:

<code class="sql">UPDATE users SET age = 31 WHERE id = 1</code>

Query (SELECT)

To To select data from a MySQL table, you can use the SELECT statement. The syntax is as follows:

<code class="sql">SELECT column1, column2, ... FROM table_name WHERE condition</code>

For example, to select all users from the users table:

<code class="sql">SELECT * FROM users</code>

The above is the detailed content of How to add, delete, modify and query mysql. For more information, please follow other related articles on the PHP Chinese website!

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