个人掌握的数据库系统命令

こ雲淡風輕ζ 提交于 2020-02-01 01:45:18

数据库本身就是一个系统性的文件夹,这个文件夹内含一些不同的文件夹,而里面装的就是一些表格。当数据信息与表格字段一一对应,相互匹配的时候,我们称他们关系型数据库。
首先数据类型分为
int 整数
varchar 字符串
decimal 浮点数
datetime 时间
创建数据库的命令
create database shujuku1
删除数据库的命令
drop database shujuku1
查看有哪些数据库
show database
使用某个数据库
use shujuku1
创建表
create table biao1
修改表的名字
alter table biao1 rename to biao2
删除表
drop table biao1

添加表的字段
alter table biao1 add newname varchar(10)
修改表的字段
alter table biao1 change biao1 biao2 int(10)
删除表的字段
alter table biao1 drop xxx

数据操纵语句
数据插入
insert into biao1(字段) value(对应的值)
数据内容修改
update biao1 set xxx(字段)=xxx where id = 1
删除数据
delete from biao1 where id=1

查询语句
select * from biao1
限定查询
select * from biao1 where name='曹操‘
select * from biao1 where salary>=2000
模糊查询
select * from biao1 where name like ‘曹%’
查找空
select * from biao1 where xxx is null
两值之间
select * from biao1 where xxx between 100 and 500
查找范围
select * from biao1 where xx>100 and xx<200
逻辑查询

select * from biao1 where age=100 and name=‘lz’

select * from biao1 where age=100 or name=‘lz’

select * from biao1 where not age=100
排序
select * from biao1 order by age desc(降序,不写就是升序)
分组
select * from biao1 group by class (按班级分组)
聚合函数
平均值
select avg(age) from biao1
求和
select sum(name)from biao1
最大值
select max(age) from biao1
限制显示
select * from limit 2 (限制只显示两条)
select * from limit 2,3 (从2条之后,显示后3条内容)
查找字段左边第一个字符
select * from biao1 where left(name,1)=‘曹’

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!