First, the library-related operations
1 .1 create a database the CREATE DATABASE database name utf8 charset; 1 .2 view the database Show Databases; Show the Create Database db1; the SELECT Database (); 1 .3 Select Database USE database name 1 .4 delete the database DROP DATABASE database name; 1 . 5 to modify the database ALTER database DB1 charset UTF8;
Second, the related operation table
2.1 Create a table
# Syntax:
Create table Table (
Field Name Type 1 [(width) constraints],
Field Name Type 2 [(width) constraints],
Field Name Type 3 [(width) constraints]
);
# Note:
1. In the same table, the same field names is not
2. an optional width and the constraints
3. The field names and types is required
2.2 See table structure
desc T1;
Show Create Table T1 \ G; # Display detailed structure, additive \ G
2.3 table modified
syntax:
1. modify table
ALTER tABLE table name
RENAME new name;
2. Add Field
ALTER TABLE table name
ADD Field Name Data Type [integrity constraints ...],
ADD Field Name Data Type [integrity constraints ...];
ALTER TABLE table name
ADD Field Name Data Type [integrity constraints ...] FIRST;
ALTER tABLE table name
ADD field name data type [integrity constraints ...] an AFTER field name;
delete field
ALTER tABLE table
DROP field name;
4. Modify the fields
ALTER TABLE table
MODIFY Field Name Data Type [integrity constraints ...];
ALTER TABLE table name
CHANGE old legacy field name field name new data type [integrity constraints ...];
ALTER TABLE table name
CHANGE old field new name for the new field name data type [integrity constraints ...];
2.4 copy table
copy record table structure + (key will not be copied: primary keys, foreign keys and indexes)
MySQL> Create new_service SELECT * from table-Service;
Copy table structure only
mysql> select * from service where 1 = 2; // condition is false, not find any records
Empty SET (0.00 sec)
MySQL> Create Table new1_service SELECT * WHERE from-Service. 1 = 2;
Query the OK, 0 affected rows (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
MySQL> the Create the Table T4 like the Employees;
2.5 Delete table
DROP TABLE table name;