MySQL Modify, delete data records

Source: Internet
Author: User
Tags command line

Sometimes, you want to drop some records or change their contents. The DELETE and UPDATE statements enable us to do this.

Modify records with update

UPDATE Tbl_name Set the column to change

The record WHERE you want to update

The WHERE clause here is optional, so if you do not specify it, each record in the table is updated.

For example, in the pet table, we found that the sex of the pet Whistler was not specified, so we can modify this record as follows:

Mysql> Update pet Set sex= ' F ' where name= ' Whistler ';

Delete Records with delete

The DELETE statement has the following format:

Delete from Tbl_name WHERE to delete records

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

This query clears all the contents of the table. You must be careful!

To delete a specific record, you can select the record you want to delete by using the WHERE clause. This is similar to the WHERE clause in the SELECT statement.

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

You can empty the entire table with the following statement:

Mysql>delete from Pet;

Summarize

This section describes the use of two SQL statements. Use the update and DELETE statements with great care because it can be dangerous for your data. In particular, DELETE statements make it easy to delete large amounts of data. Be careful when you use it.

Study Questions

1, please personally follow the steps described in this chapter, so that the MySQL server in the Linux system startup, automatically start. And try other ways to start, restart, and shut down the server.

2, now has a host database.domain.net MySQL server, with the root user's identity, the password is newpass, connect to the database test. How do I give you the right command line? If you use an option file, how do I add an option?

3. In the test database, establish a table pet described in the example in this chapter, and its structure is described as follows:

name:30 a fixed-length string of width

owner:30 a fixed-length string of width

Species:10 a fixed-length string of width

Sex: Non-null enumeration type composed of M and F

Birth:date type

Death:date type

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.