①: 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)