Tag: LOB ext Lin Time font text drop timestamp length
MySQL Create:
1. Create a database
Create Database test2;
2. Deleting 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 (primary key),
Name varchar (NOT NULL)
);
* * Self-growth auto_increment
* * PRIMARY KEY PRIMARY key
* * FOREIGN key FOREIGN key (column name) references Main Table name (column name)
* * non-null NOT NULL
4. Delete a table
drop table Ceshi;
Attention:
1. The type contains the length of the parentheses after the type, and the parentheses write the length
2. Complete the previous column with a comma
3. The last column do not write a comma
4. Add a semicolon after each SQL statement is finished
5. If there is a foreign key relationship, first create the primary table
Data types in MySQL
MySQL has three major classes of data types, number, date \ Time, string, and more detailed sub-types in the three categories:
- Number Type
- integers: tinyint, smallint, mediumint, int, bigint
- Floating-point numbers: float, double, real, decimal
- dates and times : Date, Time, DateTime, timestamp, year
- String type
- String: char, varchar
- Text: Tinytext, text, Mediumtext, Longtext
- Binary (used to store pictures, music, etc.): Tinyblob, Blob, Mediumblob, Longblob
Data types and creation in MySQL