MariaDB SQL Update and delete data

Source: Internet
Author: User

To highlight more important topics in database operations, the following is pinned.

Guidelines for updating and deleting data :

    • Do not use the WHERE clause when performing an update or delete, unless you really intend to update or delete each row.
    • Make sure that each table has a primary key, and that it is used whenever possible to use a WHERE clause.
    • Before using an update or delete with a WHERE clause, test with the SELECT statement to ensure that the correct records are filtered.
    • When using a database, referential integrity is enforced so that MARIADB does not allow the deletion of rows whose data is associated with data in other tables.

Update data
UPDATE Customers SET = ' [email protected] ' WHERE = 10005;

To update multiple columns :

UPDATE Customers SET = ' The Fudds ' ,     = ' [email protected] ' WHERE = 10005;

If you update multiple rows with the UPDATE statement, and the update one or more rows produces an error, the entire update operation is canceled.

In order to continue the update operation even if an error occurs, you can use the keyword ignore

UPDATE IGNORE customers ...

Delete column values ( not delete data ):

UPDATE Customers SET = NULL WHERE = 10005;

Delete data

DELETE  from Customers WHERE = 10006;

The DELETE statement removes a separate row from the table.

Delete always deletes the contents of the table, not the table itself. Even if all rows in the table are deleted, the DELETE statement does not delete the table itself.

Faster deletion: If you really want to clear all the rows in the table, do not use Delete, but instead use the TRUNCATE table statement.

MariaDB SQL Update and delete data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.