当前位置:网站首页>数据库(其二)
数据库(其二)
2022-08-11 05:23:00 【hqhe260】
回顾:
怎么打开MySQL服务
服务中找到自定义的服务名称 MySQL8
开启服务
如何创建数据库?
create database if not exists schoolDB;
删除数据库?
drop database if exists schoolDB;
使用数据库?
use schoolDB;
创建表?
create table if not exists tb_cls( # 列明 数据类型 约束 c_id int primary key, c_name varchar(20) not null );
create table if not exist tb_stu( s_id int primary key, s_name varchar(20) not null, s_birth date, s_sex varchar(20) default '男', c_id int, constrain fk_stu_cls foreign key(c_id) references tb_stu(c_id) );
向表中添加输入 插入操作
insert into tb_cls(c_id, c_name) values(1,'DA2002'); insert into tb_stu(s_id, s_name, s_birth, s_sex, c_id) values(1,'张三','2022-07-04','男',1);
修改表中数据 更新
update tb_cls set c_name = 'DD2002' where c_id = 1;
删除表中数据
delete from tb_cls where c_id = 1; // 能删除吗? 不能
查询表中数据
select * from tb_cls; select c_name from tb_cls; select c_name '姓名' from tb_cls;
10.课前准备
创建数据库
创建班级表
创建学生表
分别向两个表中插入数据
11 .查询全项数据(用的非常多)
select * from tb_stu;
根据主键查询数据 (定位某一条)
select * from tb_stu where s_id=1;
根据某一项查询数据
select * from tb_stu where s_name='张三';
多条件查询 (登录)
select * from tb_stu where c_id=1 and s_name='张三'; select * from tb_stu where c_id=1 or s_name='张三';
范围查询 (多选批量操作)
select * from tb_stu where s_id in(1,3,5);
结果集查询(多选批量操作)
select * from tb_stu where s_id=1 or s_id=3 or s_id=5;
模糊查询 (搜索)
查询关键字?
like
匹配不限数量字符用什么?
%
匹配一个字符用什么?
#知道姓张 两个字 select * from tb_stu where s_name like '张_';
#姓张同学的查询 select * from tb_stu where s_name like '张%';
交叉连接
什么意思?
多个表之间相互配合 一对多
左连接
什么意思?
已左边为主 进行多表联查 left join
右连接
什么意思?
已右边为主 进行多表联查 right join
边栏推荐
猜你喜欢
随机推荐
如何修改严格模式让MySQL5.7插入用户表的方式新建用户成功?delete和drop的不同
azkaban集群部署
MPLS 实验
GBase 8s性能简介
海外媒体发稿,要考虑到不同的民族文化特点
GBASE数据库迁移(Oracle到GBase 8s的数据类型映射)
DAPP系统开发及智能合约实现技术
NAT模式 LVS负载均衡群集部署
如何正确使用OPcache优化系统性能
GBase 8s集中式企业级安全事务型数据库
>>技术应用:*aaS服务定义
ES11新增数据类型BigInt大整型
利用轮播图制作简单游戏页面
静态综合复习实验
GBase 8s与Oracle存储对比
error: The following untracked working tree files would be overwritten by merge: .hbuilderx/launch
Koa的使用,搭建本地服务器(必会技能)
NodeRed系列—发送消息给emqx
代币标准--ERC1155协议源码解析
IDEA本机连接远程TDengine不成功,终于配置成功