Yesterday Review
Table 1. Operation
increase
create table 表名(
字段名 字段类型[字段约束]
....
)charset=utf8
Field Type
digital
Integer
tinyint
smallint
int *********************
mediumint
bigint
区别 :
取值的范围不一样
加上unsigned,代表只能取整数
Float
float
double
decimal(10,5)
String type
char() 定长
身份证,手机号
varchar() 变长
哈希密码
区别:
1.char(4) 'ab ' 占4个字节,剩余的不足字节用空字节补充
2.varchar(4) 'ab' 占3个字节,其中有两个是自身的大小,还有一个是记录字节的大小
Time Type
datetime**************
年月日时分秒
enumerate
enum
gender enum('male','female') default 'female';
Column constraint (optional parameters)
auto_increment 自增
not null 不能为null
primary key 主键索引
default 默认值
delete
drop table 表名;
Delete field name
alter table 表名 drop 字段名;
change
New table fields
alter table 表名 add 列声明;
alter table 表名 add 列声明 frist;
alter table 表名 add 列声明 after 字段名;
Field name changes to the table
alter table 表名 modify 字段名 字段类型[字段约束]
alter table 表名 change 旧字段 新字段 字段类型[字段约束];
check
show tables;
Operating data row
increase
insert into 表名(列1,列2) values(值1,值2),(值1,值2);
delete
delete from 表名;
自增继续加1,一行行删除
truncate 表名;
全选删除,自增键重新开始,速度快
Conditional deletion
delete from 表名 where id=10;
delete from 表名 where id=10 and name='n';
change
update 表名 set name='zekai',age=12;
Modified as conditions
update 表名 set name='zekai', age=15 where age=12 and num=10;
check
select * from 表名; 返回表中所有数据
select 列名1,列名2 from 表名;
Search by condition
select * from where id=10;
between...and...
select * from 表名 id between 30 and 40;
distinct deduplication
select distinct name from t6;
in query
select
like fuzzy query
Arithmetic
is null
Table 1. Single Operation
Packet
All data packets are classified according to a same field
group by
order
limit
2. Multi-table operations
Foreign key
3.mysql backup
create table department(
id int auto_increment primary key,
name varchar(32) not null default ''
)charset utf8;
insert into department (name) values ('研发部');
insert into department (name) values ('运维部');
insert into department (name) values ('前台部');
insert into department (name) values ('小卖部');
create table userinfo (
id int auto_increment primary key,
name varchar(32) not null default '',
depart_id int not null default 1,
constraint fk_user_depart foreign key (depart_id) references department(id)
)charset utf8;
insert into userinfo (name, depart_id) values ('zekai', 1);
insert into userinfo (name, depart_id) values ('xxx', 2);
insert into userinfo (name, depart_id) values ('zekai1', 3);
insert into userinfo (name, depart_id) values ('zekai2', 4);
insert into userinfo (name, depart_id) values ('zekai3', 1);
insert into userinfo (name, depart_id) values ('zekai4', 2);
insert into userinfo (name, depart_id) values ('zekai4', 5);