美文网首页
java成长之路-MYSQL学习笔记

java成长之路-MYSQL学习笔记

作者: iOS_ZG | 来源:发表于2017-02-27 18:17 被阅读81次
Paste_Image.png

一、数据库:存储、维护和管理数据的集合。
DBMS DB
二、sql:结构化查询语言
sql分类:
DDL:数据定义语言,对对象操作
CREATE ALTER DROP
DML:对表中的数据操作
INSERT UPDATE DELETE
DQL:数据查询语言
SELECT
DCL:数据控制语言
CRANT REVOKE
create database mydb1;
use mydb1;

create table student(
    id int primary key auto increment,//主键、自动增长
    name varchar(50) not null unique,//不为空、唯一
    sex varchar(10) default ‘男’//默认值
);

alter table student add did date;


insert into student(name,sex,gid) values(‘tow’,’女’,1);
insert into student(name,sex,gid) values(‘jerry’,’女’,2);
insert into student(name,sex,gid) values(‘scott’,’女’,1);

update student set sex=’男’,gid=3 where id=2;

select * from student where gid=(
select gid form student where name=‘tow’);

select from where group by having order by limit;

from where group by having select order by limit;

like ‘_%’ in  is null is not null between and

distinct //去除重复数据

聚合函数- - 滤空功能
sum() avg() max() min() count()

ifnull(comm,0)//去除空值

三、数据完整性
实体完整性:行级约束。 primary key unique anto_increment
域完整性 : 列级约束。数据类型,not null default
引用完整性:(参照完整性) foreign key

四、表关系
一对多(多对一)
多对多
一对一

五、多表查询
合并查询 union union all
连接查询
内连接
inner join in
外连接
left join in
right join in
自然连接
natural left
子查询
select * from student where gid=(
select gid form student where name=‘tow’);
//有2个以上直接下属的员工信息
select * from emp where empno in(select mgr form amp group by mgr having count(mgr)>=2);
//查询员工编号为7788的员工名称、员工工资、部门名称、部门地址
select e.ename,e.sal,d.dname,d.loc from emp e,dept d where e.deptno=d.deptno and empno=’7788’;
自连接(自己连接自己、起别名)
//求7369员工编号、姓名、经理编号和经理姓名
select e1.empno,e1.name,e2.empno,e2.ename from emp e1,emp e2 where e1.mgr=e2.empno and e1.empno=7369;

六、sql函数
日期函数
字符函数

相关文章

网友评论

      本文标题:java成长之路-MYSQL学习笔记

      本文链接:https://www.haomeiwen.com/subject/qjttgttx.html