Excerpt from rookie tutorial, part of the knowledge point record according to my own situation. In order to consolidate a knowledge learned, and secondly for future review.
Mysql basis Two Notes
Create a database
Create command to create a database using the following syntax:
CREATE DATABASE 数据库名;
Delete Database
Use the drop command to delete the database, the syntax is as follows:
Drop database 数据库名;
Mysql Data Types
Mysql data types include numeric, date / time and a character string (character) type.
Numeric types
- Strict numeric data types: INTGER, SMALLINT, DEDECIMAL and NUMERIC
- Approximate numeric data types: FLOAT, REAL and DOUBLE PRECISION
Date and Time Types
Including 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.
Types of | format |
---|---|
DATE | YYYY-MM-DD |
TIME | HH-MM-SS |
YEAR | YYYY |
DATETIME | YYYY-MM-DD HH-MM-SS |
TIMESTAMP | YYYYMMDD HHMMSS |
String type
Including CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM and SET.
Character length encoding related:
UTF-. 8: characters. 1 = 3 bytes
GBK: 1 = 2 bytes characters
char, varchar, text differences:
- char: fixed length, length in the range of 0-255 bytes, less than the length of the content 255, storage space filled.
- varchar: variable length, byte length in the range 0-65535.
- text: a length in the range of 0-65535 bytes, not have a default value.
tips:
- Varchar field changes often with
- Known and fixed length of 255 length of char
- Try to use varchar
- With a length of more than 255, or text varchar
- Can not text varchar
Create a data table
Syntax:
the Create the Table table name (field name field type);
Null "difference" and a NULL:
- Null does not occupy space
- NULL occupy a space
of any number of operations with NULL is NULL;
determine whether equal to NULL, = not available, use a keyword is NULL.
Insert data
Syntax:
INSERT INTO table name (field 1, field 2, field ... n) value (value 1, value 2, ... value n)
Query data
Syntax:
SELECT 1 field names, field names 2 from table [where condition]
Query All fields: "*" indicates all the fields
select * from table [where comdition]
update data
Syntax:
Update table set field value 1 = 1, the value of field 2 = 2, ..., n = the value of field 2 [where condition]
A partial data field of the replacement data:
Update table set field a = replace (a field, the character string is replaced, the new string)
delete data
Syntax:
delect from table [where condition];
if no where clause to delete all records in the table.
tips: delete delete only the table data, drop the table structure and data are deleted.
delete, drop, truncate difference:
- delete and delete only data truncate table data, drop along with the table data and table structure be deleted.
- delete is DML statements can be rolled back after the completion of soap rub. truncate and drop a DDL statement, the operation takes effect immediately and can not be rolled back.
- Execution speed: drop-> truncate-> delete