DLL: operation of the database and tables

1. Operational Database

  C (Create creation) R (Retrieve query) U (Update Update) D (Delete Delete)

  (1) to query the database

    1) Search the database name

    SHOW DATABASES;

    

     There is a note of something, a Database data directory corresponding to an entity folder, but information_schema this database has no physical counterparts. Its purpose is to use as the view, the information described in the table in the database, the name of the library or the like.

    2) Create a query statement and create the database character set

    SHOW the CREATE  DATABASE database name;

    

     Although it has been modified the default encoding of the database is utf8mb4, but have created a database or utf8. And this mysql database is Latin1, although support for Chinese, but it is best changed utf8mb4.

 

  (2) create a database

    1) Create a database

    The CREATE  DATABASE database name;

    

    2) Create a database with a judge's sentence

    The CREATE  DATABASE  IF  the NOT  EXISTS database name; 
    - If the database does not exist, create, if not created, but whether the creation of the database will return Query OK

    

    3) Create a character set specified in the database

    The CREATE  DATABASE database name CHARACTER  the SET character set;

    

 

  (3) modify the database

    1) modify the database character set

    The ALTER  DATABASE database name CHARACTER  the SET character set COLLATE collation;

    

    Here note, modify the character set the best time to modify collation. The collation utf8mb4 There are two, one is a utf8mb4_general_ci is utf8mb4_unicode_ci. Because utf8mb4_unicode_ci sort of be more accurate, it is recommended to use utf8mb4_unicode_ci sort.

 

  (4) delete the database

    1) delete (very dangerous, try not to use)

    DROP  DATABASE database name;

    

    2) delete with judgment (in case that caused the error)

    DROP  DATABASE  IF  EXISTS database name;

    

 

  (5) the use of database

    1) currently used in the database query

    SELECT DATABASE();

    

    2) access to the database

    USE database name ();

    

    After entering the database if you want to switch to another database, you can direct the USE command.

 

2. Operating Table

  (1) look-up table

    1) query the database in which tables

    SHOW TABLES;

    

    2) look-up table structure

    DESC table name;

    

    3) look-up table character set

    SHOW CREATE TABLE 表名;

    

 

 

  (2) create table

    1) Create a base table

    The CREATE  TABLE table name ( 
          Column Name Data Type, 
          Column Name Data Type, 
          Column Name Data Type 
    );

     

 

 

    2) Create a table a table has the same structure

    The CREATE  TABLE new table name LIKE old table name;

    

 

  (3) Delete table

    1) delete

    DROP TABLE 表名;

    

 

    2) delete with judgment

    DROP TABLE IF EXISTS 表名;

    

 

  (4) modify the table

    1) Modify the table name

    The ALTER  TABLE table RENAME the TO new table name;

    

 

    2) modify the character set table

    The ALTER  TABLE table name CONVERT  the TO  CHARACTER  the SET character set COLLATE collation;

    

 

    3) Add Column

    The ALTER  TABLE table name ADD Column Name Data Type;

    

 

    4) modify the column names and data types

    The ALTER  TABLE table name CHANGE column names new column name for the new data types;

    

 

    Type 5 data) modified column

    The ALTER  TABLE table MODIFY column names new data types;

    

 

    6) Delete Columns

    The ALTER  TABLE table DROP column names;

    

Guess you like

Origin www.cnblogs.com/NyanKoSenSei/p/11444851.html