标签:roman 设置 查看 ack ext delete default res str
E-R模型(实体关系模型)
数据引擎
MyISAM和InnoDB的区别
三范式
字段类型
约束
远程连接
数据库
数据表
alter table 表名 add|change|drop 列名 类型;
如:
alter table students add birthday datetime;
drop table 表名;
desc 表名;
rename table 原表名 to 新表名;
show create table ‘表名‘;
数据操作
select * from 表名
全列插入:insert into 表名 values(...)
缺省插入:insert into 表名(列1,...) values(值1,...)
同时插入多条数据:insert into 表名 values(...),(...)...;
或insert into 表名(列1,...) values(值1,...),(值1,...)...;
update 表名 set 列1=值1,... where 条件
delete from 表名 where 条件
alter table students add isdelete bit default 0;
如果需要删除则
update students isdelete=1 where ...;
清空表
-- 清空全部数据,不写日志,不可恢复,速度极快
truncate table 表名;
-- 清空全部数据,写日志,数据可恢复,速度慢
delete from 表名
查看字符集
show variables like ‘%char%‘;
数据备份
sudo -s
cd /var/lib/mysql
mysqldump –uroot –p 数据库名 > ~/Desktop/备份文件.sql;
按提示输入mysql的密码
数据恢复
mysql -uroot –p 数据库名 < ~/Desktop/备份文件.sql
根据提示输入mysql密码
数据查询(where中的优先级)
数据查询(where和having 的区别)
数据聚合操作
数据分组
排序
去除重复行
外键的设置
create table scores(
id int primary key auto_increment,
stuid int,
subid int,
score decimal(5,2),
foreign key(stuid) references students(id) on delete cascade,
foreign key(subid) references subjects(id)
on delete cascade
);
alter table scores add constraint stu_sco foreign key(stuid) references students(id) on delete cascade;
连表查询
select students.sname,subjects.stitle,scores.score
from scores
inner join students on scores.stuid=students.id;
注:inner join ...on...左右的表明无所谓顺序,读取两个表的全部字段
left join...on... 和 right join...on... 查询其中一个的全部数据字段,另一个没有也无所有,null填充
标签:roman 设置 查看 ack ext delete default res str
原文地址:http://www.cnblogs.com/yy601222543/p/7819849.html