数据库(黑马)

数据库

复制代码
use test2;
show tables;
create table student2(
    id int,
    name varchar(10),
    sex varchar(10)
);
ALTER TABLE student  ADD sex int;
INSERT INTO student (sex) VALUES ('1');
insert into student(id) values(1),(2),(3);
insert into student2  values(4,'呆呆1',19),(5,'hedfdshe',18),(6,'pdd',13);
delete from student where id=3;
update student  set name='yuanshen' where id=5;
select id,name,age from student ; 
select * from student where id=6 ; 
select sex,avg(id),sum(id) from student2 group by sex ;
select  * from student2 where sex=18 order by id desc ;
select  * from student2 limit 2,3;
select sex,count(*) from student2 where sex > 10 group by sex order by sex ;
​
DDL

层级关系 库>>表>>数据

注释 -- 我是注释 # 我是注释 /* 多行注释 */

库操作

显示有哪些数据库 SHOW DATABASES;

使用数据库 USE 数据库名称;

创建数据库 CREATE DATABASE 数据库名称 CHARSET UTS-8;

删除数据库 DROP DATABASE 数据库名称;

查看当前使用的数据库SELECT DATABASE();

表操作

首先使用库,才能以此为基础操作表

use 库名;

显示表 show tables;

创建表

复制代码
create table student1(
​
    id int,
​
    name varchar(10),
​
    age int
​
);

删除表 drop table student;

DML数据操作

where 条件判断; 可写可不写,不写默认全部 字符用单引号引起来

插入

语法 INSERT 表列1,列2,。。。 VALUES(值1,值2,。。。)

insert into student (id,name,age) values(5,'呆呆',19),(6,'hehe',18)

删除

语法 DELETE FROM 表名称 WHERE 条件判断; = < > <= >= !=

delete from student where id=3; delete from student;删除整张表的内容

更新

语法 UPDATE 表名 SET 列=值 WHILE 条件判断

DQL

数据查询

select 字段列表|* from 表

查询所有列 select id,name,age from student ; select * from student ;

查询指定列 select * from student where id=6 ;

分组聚合

sum求和 avg求平均值 min最小值 max最大值 count求数量

select 字段|聚合函数 from 表 where 条件 group by 列; 可以写多个聚合函数

select gender,avg(age) from student group by gender;

排序和分页

对查询到的结果进行排序(按照id,以asc升序排列) select * from student2 where sex=18 order by id asc ;

分页 对查询的结果限制只输出从第2行以后开始,往后输出3行 select * from student2 limit 2,3; limit在语句最后

相关推荐
sky_8106131 小时前
Oracle ERP 各模块业务管理功能及底层表说明
数据库·oracle
YMatrix 官方技术社区2 小时前
CittaBase vs. Neo4j :原生图性能实测与混合检索实践
数据库·功能测试·ymatrix
闲猫3 小时前
LangChain / Integrations / Integrations by component / Tool
java·数据库·langchain
xqqxqxxq4 小时前
SQL 连接查询技术笔记
数据库·笔记·sql
Databend4 小时前
从万亿级大模型到全线应用:Databend Cloud 助力头部 AI 企业构建全链路 Trace 数据管道
大数据·数据库·sql
MC皮蛋侠客4 小时前
SQLAlchemy 系列(十一):从 1.x 到 2.x——渐进迁移与数据访问层治理
数据库·python
1001101_QIA4 小时前
工控机网络配置
开发语言·数据库·php
ClouGence5 小时前
加一张临时表,OceanBase Oracle 写入居然快了 30 倍!
数据库·sql·oracle
tju23335 小时前
信创产业二十年:国产基础软件走到哪一步了?
数据库·gitee