Some of MySQL's recorded operations

Source: Internet
Author: User

①: Deleting table records

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. Must be careful!

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

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

Or

Mysql>delete from user where uid=1;

You can empty the entire table with the following statement:

Mysql>delete from Pet;

② Insert Record:

Inserts are used to insert new rows into an existing table. INSERT ... The values statement inserts a row according to a value that is explicitly specified. Let's first look at the definition of the INSERT statement standard, which can be omitted from the []:

INSERT [low_priority|DELAYED|high_priority][IGNORE]

[ into]Tbl_name[(Col_name,...)]

VALUES({Expr|DEFAULT},...),(...),...

[ onDUPLICATE KEYUPDATECol_name=Expr,...]

This syntax is very simple, according to the meaning of English words can be translated directly: Insert Table name (Field 1, Field 2) values (the value of field 1, the value of field 2);

Insert Statement Example:

To illustrate the effect, let's create a MySQL data table with the following structure to facilitate some of the subsequent examples:

Create table links (name varchar(255) NOT null default ' ',   address varchar(255) not null default ');

Insert a data, name set to Xiaoming,address set to GDSZ can use the following syntax

Insert into links(name, address) values (' xiaoming ',' Gdsz ') ;

③ Deleting a database

The drop command is used to delete a database.

Drop command format: Drop databases < database name >;

For example, delete a database named XHKDB:
mysql> drop Database xhkdb;

[Example 1] Delete a database that has been determined to exist:
mysql> drop Database drop_database;
Query OK, 0 rows Affected (0.00 sec)

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.