(DELETEUPDATE) modify and delete data record _ MySQL

Source: Internet
Author: User
(DELETEUPDATE) modify or delete data records. sometimes, you want to remove or modify some records. The DELETE and UPDATE statements allow us to do this.

Modify record with update

UPDATE tbl_name SET column to be changed

WHERE record to be updated

The WHERE clause is optional. Therefore, if not specified, each record in the table is updated.

For example, in the pet table, we find that the gender of the pet Whistler is not specified, so we can modify this record as follows:

Mysql> update pet set sex = 'F' where name = "Whistler ";

Delete a record

The DELETE statement has the following format:

Delete from tbl_name WHERE record to be deleted

The WHERE clause specifies which records should be deleted. It is optional, but if it is not selected, all records will be deleted. This means that the simplest DELETE statement is also the most dangerous.

This query clears all contents in the table. Be careful!

To delete a specific record, you can use the WHERE clause to select the record to be deleted. This is similar to the WHERE clause in the SELECT statement.

Mysql> delete from pet where name = "Whistler ";

You can use the following statement to clear the entire table:

Mysql> delete from pet;

Summary

This section describes the usage of two SQL statements. Be careful when using the UPDATE and DELETE statements, because it may cause danger to your data. Especially the DELETE statement, it is easy to DELETE a large amount of data. Be careful when using it.

Questions

1. follow the steps described in this chapter to enable the MySQL server to automatically start when the Linux system is started. Try other methods to start, restart, and shut down the server.

2. now there is a MySQL server located in the host database.domain.net. use the root user's identity and password newpass to connect to the database test. How can we provide appropriate command lines? If the option file is used, how do I add the option?

3. create a table pet described in the example in this chapter in the test Database. its structure is described as follows:

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.