MySQL Data Type and creation, mysql Data Type Creation
MySQL creation:
1. Create a database
Create database test2;
2. delete a database
Drop database test2;
3. Create a table
Create table ceshi
(
Ids int auto_increment primary key,
Uid varchar (20 ),
Name varchar (20 ),
Class varchar (20 ),
Foreign key (class) references class (code)
);
Create table class
(
Code varchar (20) primary key,
Name varchar (20) not null
);
** Auto-increment auto_increment
** Primary key
** Foreign key (column name) references main table name (column name)
** Non-null not null
4. delete a table
Drop table ceshi;
Note:
1. If the type contains the length, brackets are added after the type, and the length is written in brackets.
2. Add a comma (,) to the last column.
3. Do not enter a comma in the last column.
4. Add points after each SQL statement is written
5. If there is a foreign key relationship, first create a master table
Data Types in MySQL
MySQL has three types of data: numbers, dates, times, and strings, which are further divided into multiple subtypes:
- Numeric type
- Integer: tinyint, smallint, mediumint, int, bigint
- Floating Point: float, double, real, decimal
- Date and Time: Date, time, datetime, timestamp, year
- String type
- String: char, varchar
- Text: tinytext, text, mediumtext, longtext
- Binary (used to store images and music): tinyblob, blob, mediumblob, and longblob