1. Introduction to the database
(1), what is a database?
A file, a folder, a u disk, a hard disk... They are all called database warehouses for storing data
(2), common database?
mySql sqlServer mongodb oracle......
(3), the point of the database
1. Use structured query language SQL to access the database
2. Support linux mac os, windows and other operating systems
3. Provide API for multiple programming languages such as C java php. . .
4. Open source, no extra cost
5. Provide management tools for managing, checking and optimizing the database
(4) The data in the database is stored in the table, the table is composed of rows and columns, and the columns are also called fields
2. Basic understanding of field types in tables
(1), field type---string
Data Type Meaning
char up to 255 characters
varchar up to 65532 characters
tinytext up to 255 characters
text up to 65535 characters
mediumtext up to 2 to the power of 24 - 1 character
longtext up to 2 to the power of 32 - 1 character
When you set the field type to VARCHAR or CHAR, you need to specify the length value
(2), field type - time
Data Type Meaning
date date, format: YYYY-MM-DD
time Time, format: HH:MM:SS
datetime Date time, format: YYYY-MM-DD HH:MM:SS
timestamp has the same function as detetime (but with a smaller range)
year year, format: yyyy
![](https://images2018.cnblogs.com/blog/917454/201804/917454-20180422230851514-1788741740.png)
3. Field properties
unsigned:
If unsigned is set, only positive numbers can be stored
For example, amount, order id, user id, etc.
zerofill:
Define an unsigned value , the corresponding value range is doubled
When the length of the inserted column is less than the defined length, it will automatically add 0 to the front. This attribute is used together with unsigned
binary:
Only used for char and varchar values, when the field specifies this attribute, it will be sorted in a case-sensitive manner
![](https://images2018.cnblogs.com/blog/917454/201804/917454-20180422231146764-956813803.png)
4、NULL&&NOT NULL
The column can remain empty when the null attribute is specified
If a column is defined as not null, inserting null values into the column will not be allowed
Checked: Can be empty
Unchecked: cannot be empty
![](https://images2018.cnblogs.com/blog/917454/201804/917454-20180422231128476-654790108.png)
5. Index
(1), MySQL indexes mainly include the following
1. Primary key index: primary
2. Unique index: unique
3. Index: index
4. Global index: fulltext
Primary key index: is a special unique index, a table can only have one primary key, no null values are allowed
Unique index: The value of the indexed column must be unique, but null values are allowed
Index: This is the most basic index, it has no restrictions, and it is the index we use in most cases.
Global indexes: MySQL supports full-text indexes and full-text searches since version 3.23.23. FULLTEXT indexes can only be used on MyISAM tables; they can be created from CHAR, VARCHAR, or TEXT columns as part of a CREATE TABLE statement, or subsequently using ALTER TABLE or CREATE INDEX is added.
Can be created on columns of type char, varchar or text
(2)、索引的优点及缺点:
优点:
大大加快数据查询速度
通过创建唯一索引,保证数据库表每行数据的唯一性
缺点:
维护索引需要耗费数据资源
占用磁盘空间
影响对表的数据进行增删改的速度
6、auto_increment
当存在并发的时候
自动生成整数值
新值为上一次插入的值+1
只适用于整数列
必须有唯一索引
必须具备NOT NULL属性
A_I就是auto_increment的缩写
![](https://images2018.cnblogs.com/blog/917454/201804/917454-20180422231100571-826483809.png)