MySQL

1:Mysql数据库:

1) mysql:

mysql数据库一般都是在中小型企业中使用,oracle则是在大型企业中使用,

mysql中的数据库: 

information_schema   数据库的元信息         mysql : 数据库用户信息,以及配置信息

test : 数据库的测试    performance_schema : 数据库的性能数据

2) 对数据库的操作:

show databases ;  显示所有的数据库        create database 数据库名;   创建一个数据库

drop database 数据库名 ;  删除一varchar个数据库

3) 对表的操作:

create table stu(id int, name varchar(20)) ;  创建一个表            drop table stu ; 删除表  

alter table stu add column age int ;  向stu表中添加age一列

alter table stu modify column age varchar(20) ;  修改age的数据类型

alter table stu change column age  gender varchar(2) ; 修改age这一列

alter table stu drop column age ; 删除一列

insert into stu values(1,'zs') ;   向表中添加数据

update table stu set name = 'ls' where id = 1;  修改id=1的name数据

delete from stu where id = 1; 删除id=1 的数据

select * from stu where id = 1; 查看id=1的信息

4) 查询操作

查询时指定别名 :  select id as '序号' ,name as '姓名' from stu;

查询时取除重复的数据 : select distinct name from stu ;

判空条件 :  select * from stu where name is not null  and name <> '';  查找名字不为null和不是''的数据;

模糊条件查询 :  select * from stu where name like '李%' ;  查询姓李的人,  ('李_' 只有 '李X') 

聚合函数查询 :  max() , min() ,avg() ,count() ;

分页查询 : select * from stu limit 2,2 ;   查看2以后的2个数据为一页

查询后排序 :  select * from stu order by id desc ;  按照id 降序;

分组查询 :  select sex,count(sex) from stu group by sex ; 统计不同性别的人数

5) sql语句分类:

DDL : 数据库定义语句  create alter drop

DML : 数据库操作语句  insert update delete

DQL : 数据库查询语句  select show

6) 数据库约束:

默认值约束 :  default ;   非空约束 : not null ;  唯一约束 :  unique ;

主键约束 : primary key ;  自增长 :  auto_increment ;

外键约束 : constrant fk foreign key stu(classId) reference class(id);

7) 级联操作

级联操作的前提是有外键约束,

on update cascade  on delete cascade 

8) 数据库设计:

第一范式: 每一个表的字段都有独立的名称,

第二范式: 每一个表的其他字段和主键都有一个的依赖关系,(一张表只表达一个意思)

第三范式: 每一个表的其他字段和主键都是决定性关系,

9) 存储过程:

delimiter $

create procedure 存储过程名称(形式参数)

begin

sql 语句

end;


call 存储过程名称(实际参数) ;  调用存储过程


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值