Basic operations and data types of the database

Database operations
- 1. Create a database (corresponds to create a folder on the disk)
    the CREATE DATABASE [IF the NOT EXISTS] database name [CHARACTER SET xxx] --xxx to utf8 or GBK
                                                               - [IF the NOT EXISTS] meaning of this option If the table does not exist is created, if there is no table is created.
                 
- 2. Check the database
    SHOW DATABASES; - View all database
    SHOW CREATE DATABASE library name; - to see how the database is created
- 3. Modify database
    ALTER DATABASE database name [CHARACTER SET xxx]; - (generally not required)
- 4. Delete database
    DROP DATABASE [IF EXISTS] database name;
   
- 5. Use Database
    USE library name; - switching database
              - Note: No way back into a database and then returned to its previous state, but you can USE switch
    SELECT dATABASE (); - View the current database
MySQL data types
 MySQL supports multiple types can be roughly divided into three categories: the value, date / time and a character string (character) type.
Numeric types
The following table shows the range of each storage and integer type required.
- integer type
value of the number of bytes unsigned Type Value Type Value Number of symbol types
TINYINT. 1 (0,255) (-128,127)
SMALLINT 2 (0,65535) (-32768, 32767)
MEDIUMINT. 3 (0,16777215) (-8388608,8388607)
the INT. 4 or INTEGER (0,4294967295) (-2147483648,2147483647)
BIGINT. 8 (0,18446744073709551615) (-9223372036854775808,9223372036854775807)
- floating-point and fixed-point type type
value type bytes None number symbol value type value type signed number
FLOAT. 4
DOUBLE. 8
DECIMAL (M, D) M + 2
   - Note DECIMAL type DOUBLE the same type range.
   - Note that the effective range of DECIMAL type is determined by M and D.
   - where, M is the length of the data represented by the length after the decimal point.
  
- date and time type
indicates the date and time value for the type of the time DATETIME, DATE, TIMESTAMP, TIME, and YEAR.
Each type has a value of time effective range and a "zero" value of "zero" when the value of the specified unlawful MySQL can not be represented.
Type Number of bytes (size) range format uses   
DATE 3 1000-01-01 / 9999-12-31 YYYY-MM -DD date value
TIME 3 -838: 59: 59/838: 59: 59 HH: MM: SS Time value or duration
YEAR 1 1901/2155 YYYY year value
DATETIME 8 1000-01-01 00: 00: 00 / YYYY-MM-DD mixed date and time values
          9999-12-31 23:59:59 HH: MM: SS              
TIMESTAMP 4 1970-01-01 00: 00: 01 / YYYY-MM-DDH mixed date and time values
          2038-01-19 03:14:07 HH: MM: SS Number of time
- string type
string type refers to CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM and SET.
This section describes how these types work and how to use these types in a query.
Type Number of bytes (size) use
CHAR 0-255 byte fixed-length byte character
VARCHAR 0-65535 byte variable length byte character
BLOB 0-65535 bytes long text data in binary form
TINYBLOB 0-255 bytes does not exceed binary string 255 characters
intermediate length text data byte binary form MEDIUMBLOB 0-16777215
LONGBLOB 0-4294967295 bytes of text data in binary form greatly
tEXT 0-65535 bytes of text data
TINYTEXT 0-255 bytes short text string
MEDIUMTEXT 0-16777215 byte of middle length of the text data
LONGTEXT 0-4294967295 maximum byte text data
/ * CHAR type VARCHAR, and the like, but they are different ways to save and retrieve. Their maximum length and whether trailing spaces are retained, it is also different. In the case conversion is not performed during the storage or retrieval.
   BINARY and VARBINARY type is similar to CHAR and VARCHAR, except that they contain binary strings rather than non-binary strings. That is, they contain byte strings rather than character strings.
   A BLOB is a binary large object, can hold a variable amount of data. There are four BLOB types: TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB. They differ only in length can accommodate the maximum values.
   TEXT There are four types: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. These types correspond to four kinds of BLOB, the maximum length and have the same storage requirements.
 * /

Guess you like

Origin www.cnblogs.com/lixiangyi200174/p/11729987.html