mySQL:day01---mySQL的基础内容

一、数据库设计

E-R设计:概念设计 亿图图示(破解版)
主键:不能为空,是唯一的,是自增长的
外键:逻辑外键,两张表右关联关系,就用外键
圆圈:属性
长方形:表
关系:菱形 欢迎使用Markdown编辑器写博客

物理设计:
完整性约束
元祖是表里的每行的记录
表 元祖 记录

第一范式:
把所有的列都化成最小的单位,不能再拆分。
第二范式:
每张表只能表达一个事物,每个表里具体的属性必须只依赖于这个主键
第三范式:

创建表:
Create table student(
Sid int(4) primary key auto_increment comment”学生的编号”,
Sname varchar(20) comment”学生的姓名” ,
Spwd varchar(20) comment”学生的密码”,
createDate date comment”时间”

Use test;
描述 desc student;

添加属性:
Alter table student add sresult int(30);

改变属性:
alter table student change sname sname varchar(30);

删除属性
Alter table student drop sgrade

改表名字:
Rename table student to stu;

二、DML:insert delete update

Insert 语句
Insert into stu(col2,col3) values(val2val3)
日期单引号,字符双引号

创建:单条
Insert into stu values(1,”stella”,”123”,’2018-07-30’);
Insert into stu(sname) values(“admin”,”123”)

多条
Insert into stu values (3,”li”,”123”.’2018-07-28’),(4,”lim”,”123”.’2018-07-28’),
(5,”ddwg”,”123”.’2018-07-28’),(6,”lrty”,”123”.’2018-07-28’),(7,”l2”,”123”.’2018-07-28’),
(8,”rtf”,”123”.’2018-07-28’),(9,”lig”,”123”.’2018-07-28’),(10,”lg”,”123”.’2018-07-28’)

insert into stu(sname,spwd,createDate) values(”ff”,”321”,’2017-10-23’),(”de”,”321”,’2017-10-23’);

修改:
update stu set sname=”stew” where sid=8;

删除:
delete from stu where sid=10;
delete from stu where 8>=sid>=6;
delete from stu where sid>=9 and sid<=7;

三、where关键字

Between and

select company,quatity from product where quatity between 8000 and 12000; ===
select company,quatity from product where quatity>=8000 and quatity<=12000;

Or 和in
select company,quatity from product where quatity = 8000 or quatity = 12000; ===
select company,quatity from product where quatity in(8000, 12000);

Is not null 和is null
select company,pname,ptime from product where pname is not null;

select sum(quatity) from product group by company;
select company, sum(quatity) from product group by company;

最大值、最小值、平均值:
select pid,company, min(quatity) from product order by company;
select pid,company, max(quatity) from product order by company;
select pid,company, AVG(quatity) from product order by company;

查询数量:
查索引为1时的记录:select count(1) from product;
查全部的记录:select count(*) from product; ———–这个消耗太大,不推荐

like模糊查询:
select * from product where company like “%公司%”;
select * from product where company like “%公司_%”;—–公司1

分页:
查前两条数据
select * from product where pid<3;
不知id的情况下查前两条数据:
分页查询:mysql索引是从0开始,关键字limit 第一个参数是当前索引,第二个参数页量

select * from product limit 0,2;
第一个参数:(pagindex-1)*pagesize。
第二个参数:pagesize。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值