MySQL study notes 1 - DDL

DDL

1. Database

* View all databases: SHOW DATABASES;
* switch (select operation) database: USE database name;
* create the database: the CREATE DATABASES [IF the NOT EXISTS] mydb1 [CHARSET = utf8];
* delete the database: DROP DATABASES [IF NOT EXISTS ] MYDB1;
* Review encoding database: ALTER dATABASES mydb1 CHARACTER SET utf8;

2. Data type (column type)

int: Integer
double: float, e.g. double (5,2) indicates that up to 5, which must have two decimal places, i.e., the maximum value is 999.99
decimal: float, the use of this type of form in terms of money, because they do not lack of precision occurs
a fixed-length string type; char (255): char
VARCHAR: variable-length string type; VARCHAR (65535), zhangsan
text (CLOB): string type
  small -> tinytext (2 ^ 8- 1B)
  small -> text (2 ^ 16-1B)
  in -> mediumtext (2 ^ 24-1B)
  large -> LONGTEXT (2 ^ 32-1B)
BLOB: byte type
  small -> tinyblob (2 ^ 8- 1B)
  small -> blob (2 ^ 16-1B)
  in -> mediumblob (2 ^ 24-1B)
  large -> LONGBLOB (2 ^ 32-1B)
dATE: date type, format: the MM-dd-YYYY
Time: time type, format: HH: mm: SS
timestamp: timestamp type

3. Table

* Create the table:
 the CREATE TABLE [IF the NOT EXISTS] table (
  column among the types
  listed among the types,
  ...
  column ranked types
 );
* View current database of all table names: SHOW TABLES;
* View the specified table create a statement: SHOW cREATE tABLE table name;
* see table structure: DESC table name;
* delete table: DROP tABLE table name;
* modify the table: ALTER tABLE table name
  -> add, modify table list:
   the ALTER tABLE table name ADD (
    column among the types
    listed among the types,
    ...
   );
  -> modify the table column types of modifications: ALTER tABLE table mODIFY column ranked types;
  (if the modified column data already exists, new types may affect to existing data)
  -> modify to modify the table column names of: ALTER tABLE table name CHANGE original column names among the new column type;
  -> delete column modify the table: ALTER tABLE table DROP column name;
  -> modify to modify the table table name: ALTER tABLE table RENAME TO new original table name;

Guess you like

Origin www.cnblogs.com/silentteller/p/11788240.html