MySQL database detailed teaching-from the download and installation of Mysql and visualization tools to the summary of key knowledge

It doesn't cost much, let's start the summary of Mysql directly:

1. The download and installation of MySql will not be introduced here. There are many tutorials in csdn. Sqlyog is recommended as a visualization tool. Of course, Mysql-front, etc. are all available. You can download and install it according to your own situation.

Two, operating the database

 1. Create a database (the code in [] can be added or not):

create database [if not exists] 数据库名

2. Delete the database

drop database [if exists] 数据库名

3. Use the database

use 数据库名

4. View the database

show databases //查看所有数据库

Three, the type of field

1. Numerical type: 
bigint: it can be used only when the integer value exceeds the int data range

int: is a function that rounds down a value to the nearest integer 

smallint: An integer that requires 2 bytes to store. 

tinyint: If the TINYINT type field is set to UNSIGNED type, it can only store integers from 0 to 255, and cannot be used to store negative numbers. If the TINYINT type field does not set the UNSIGNED type, an integer from -128 to 127 is stored. 

Decimal: Belongs to the floating-point number type. The storage data range is: -1038~1038-1 with fixed precision and decimal places. A decimal type of data occupies 2 to 17 bytes. 
numeric: ​numeric(P,S) The default value of P is: 38 The default value of S is: -84~127. The numeric(a,b) function has two parameters. The first one is the total number of digits, and the latter parameter is the number of digits after the decimal point. For example, numeric(5,2) is the number of digits after the decimal point is 5, and the number after the decimal point is 2 digits. Number, which means that the integer digits of this field are up to 3 digits. 

Float: Single-precision floating-point type, the number of bytes is four, the effective bit is 8 bits, the range: -3.40E+38 ~ +3.40E+38  

double: double-precision floating-point type, the byte is eight, the effective digit is 16 bits, the range: -1.79E+308 ~ +1.79E+308 

Money: The float type is the same data type as the money type. The money type is just displayed in the data table with a $ style symbol in front of it, which makes the customer look comfortable and easy to edit. In fact, it is the same type of data as float. 

real: used to store single-precision floating-point numbers (stored in 4 bytes) 

Bit: It only represents a bit. The Bit data type is stored as 1, 0 in the SQL Server database. When adding to the database and modifying the bit type field, only 0 or 1 can be used.  

2. Character data type 

char(10): Save a fixed-length string. When storing, it is assumed that there are six characters, which is not enough ten, but it still needs to occupy ten digits regardless of whether it is enough ten digits or not, and fill in spaces if it is not enough . 

Nchar(10): Similar to the Char data type, the difference is that the value of the Nchar data type n is 1~4000. How many digits does its data storage occupy? Six digits occupies six digits, and nine digits occupies Nine digits will not occupy ten digits. Of course, it overflows. If there are too many digits, it will not fit in.  

Varchar: Save variable-length strings, varchar and char are the same character type, differently, varchar is more flexible and accurate than char, and does not occupy memory space. When you take the same character, such as field 5, when you use varchar to remove "aa" from the field, you take "aa", if you use char, you get "aa", and char will be filled in the back Five spaces. 
Nvarchar: Similar to varchar data type, the difference is that the value of Nchar data type n is 1~4000, 

text: Store a string with a maximum length of 65535 characters.  

ntext: Similar to the Text data type, the data stored in it is usually characters that can be directly output to the display device. The display device can be a monitor, a window, or a printer. The Ntext data type uses the Unicode standard character set, so its theoretical capacity is 230-l (l, 073, 741, 823) bytes. 

3. Date and time data types 

date(): date. The format is YYYY-MM-DD, and the range is 1000-01-01 to 9999-12-31 

datetime: The combination of date and time. Format: YYYY-MM-DD HH:MM:SS (The range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59, the precision is 3.33 milliseconds) 

smalldatetime: The same as datetime, but the range is reduced and the precision is reduced. (The range is 1900.1.1-2079.12.31, the accuracy is one minute) 

time(): Time. Format: HH:MM:SS The range is from -838:59:59 to 838:59:59  

year(): Format: YYYY or YY The range of YYYY is 1901 to 2155, and the allowed value of YY is 70 to 69, which means the year from 1970 to 2069, a whole hundred years. 

Four, field attributes

Unsigned: unsigned integer (cannot be declared as a negative number)

Auto-increment (auto_increment): automatically add 1 to the previous record, usually used to design the primary key, must be an integer type, you can customize the starting position and step length of the primary key auto-increment

zerofill: 0 fill, use 0 to fill the insufficient digits

Non-empty (null/not null): Set to not null, you must assign a value to the field; set null, if you do not fill in the value, the default is null

Default: Set the default value, if the value of the field is not given, the set default value will be displayed

 

Guess you like

Origin blog.csdn.net/qq_44624536/article/details/115017015