The so-called build table is the process of declaring a column:
The data is placed on the hard disk in the form of a file (also in memory)
Columns: Different column types take up less space
The principle of election: enough and not wasted;
MySQL data type:
Shaping: Tinyint (1 bytes) Smallint (2 bytes) mediumint (3 bytes) int (4 bytes) bigint (8 bytes);
Tinyint is signed in MySQL by default ( -128----127);
Tinyint (M) unsigned Zerofill
Unsigned: is unsigned, affecting the storage range;
M stands for width, (only meaning when Zerofill must be matched)
Zerofill 0 Fills, if a column is Zerofill, the default is unsigned (similar to 00005);
Insert into CLASSS (name, age4) VALUES (' Zhaoliu ', 9);
A column can declare a default value, and it is recommended to declare the default value
Not NULL default 0
ALTER TABLE class add AGE5 tinyint not null default 0;
Decimal type/floating point type:
Float (M, D)
Decimal (M, D)
M: Accuracy (total number of digits, not including points) D: scale (decimal)
CREATE TABLE Goods (
Name varchar (TEN) NOT null default ' ',
Price Float (6, 2) is not NULL default 0.00)//9999.99,-9999.99
Price Float (6, 2) unsigned NOT NULL default 0.00)//0-9999.99,
CharSet UTF8;
Inert into goods
(Name, Price)
Values
(' treadmill ', ' 688,896 ')
The value of price recorded in the table is 688.90
ALTER TABLE goods add Bigprice float (9.2) NOT null default 0.0;
ALTER TABLE goods add Deciprice decimal (9.2) NOT null default 0.0;
ALTER TABLE goods (name, Bigprice, Deciprice)
Values
(' Bicycles ', 1234567.23, 1234567.23);
Character type
Char fixed length string char (m), m for width, number of characters to hold;
varchar variable length string varchar (m), m for width, number of characters to hold;
Difference:
Char fixed length: M characters if the deposit is less than m characters, the actual account is m characters; utilization is 100%.
varchar variable length: M characters if the deposit is less than m characters, assuming N, real account for n characters;
The actual characters need to be recorded consuming 1--2 characters; (n+1~2) characters are actually occupied;
char and varchar selection principles:
1, space utilization efficiency;
2, speed;
Four-character idiom table, char (4);
Personal micro-blog, varchar (140);
User name: Char, sacrificing space, providing speed;
Text string, compare large paragraphs of text, speed slightly slower;
Note: text does not add the default value, plus does not take effect;
CREATE TABLE Stu (
Name Char (8) NOT null default ' ',
Waihao varchar (+) NOT null default ' '
) CharSet UTF8; Name accommodates up to 8 UTF8 characters;
Insert into Stu (name, Waihao)
Values
(' Zhangxiaosan ', ' saner '); The Zhangxiaosan is too long to be broken in.
Insert into Stu (name, Waihao)
Values
(' Zhangsan ', ' saner ');
Insert into Stu (name, Waihao)
Values
(' Mohammed ', ' async lachine ');
Select concat (name, '! '), concat (Waihao, '! ') from Stu;
ALTER TABLE STD ADD info text not null default ';
Execution error, no default value;
MySQL data type