当前位置:网站首页>Review summary of database
Review summary of database
2022-06-27 12:33:00 【Fisherman Abu】
List of articles
1. Operating the database
Database creation , Database selection , Delete database , View all databases , View the database in use
# Create database ( Default character set )
create database day01;
create database day01_0;
# Select database
use day01;
use day01_0;
# View the database in use
select database();
# Delete the specified database
drop database day01_0;
# View all databases
show databases;
2. Operation table
The creation of a table
Add fields in the table
Modify the properties in the field
Change the name of the field
Delete field
Show all the tables
The structure of the display table
# Create a student table
create table t_stu(
stu_id int primary key auto_increment ,
stu_name varchar(20) unique,
stu_gerder char(1) not null
);
# by t_stu Add a field to the table
alter table t_stu add stu_grade varchar(20) not null;
# take t_stu surface stu_grade Change the field type to int
alter table t_stu modify stu_grade varchar(20);
# take t_stu surface stu_grade Change the field name to class
alter table t_stu change stu_grade class varchar(20) not null;
# take t_stu In the table class Field to delete
alter table t_stu drop class;
# Show all the tables
show tables;
# The structure of the display table
desc t_stu;
# Delete table
drop table t_stu;
3. Records in the operation table
preparation
create table product(
pid int primary key auto_increment,
pname varchar(40) ,
price double ,
num int
);
3.1 Additions and deletions
increase
insert into product values(null,' Apple computer ',18000.0,10);
insert into product values(null,' Huawei 5G mobile phone ',3000,20);
insert into product values(null,' Mi phones ',1800,30);
insert into product values(null,'iPhonex',8000,10);
insert into product values(null,'iPhone7',6000,200);
insert into product values(null,'iPhone6s',4000,1000);
insert into product values(null,'iPhone6',3500,100);
insert into product values(null,'iPhone5s',3000,100);
insert into product values(null,' instant noodles ',4.5,1000);
insert into product values(null,' coffee ',11,200);
insert into product values(null,' Mineral water ',3,500);
modify
# Modify the operating
# Set the price used to 8000
update product set price=800 ;
# Apple's price Set to 18000
update product set price=18000 where pname=' Apple computer ';
# Take Xiaomi's mobile phone price Set to 1800,num Set to 10
update product set price=1800,num=10 where pname=' Mi phones ';
# Bring down the price of Apple computers 1000
update product set price=price-20 where pname=' Apple computer ';
Delete
# Delete the records used
delete from product01;
delete from product01 where pname=' Banana ';
3.2 Inquire about
Simple query
# Simple query
# Query all data
select * from product;
# Query specific columns ( Field )
select pid, pname, price from product;
# Alias query
select pname The product name ,price Price from product ;
# Go to check again distinct
select distinct price,num from product;
# Arithmetic query
select price+180000 Price after change ,num from product;
Conditions of the query
# Conditions of the query where
select * from product where price>800 or num>200;
select * from product where price>=800 and num=200;
# Fuzzy select * from product where pname like "iPh%";
# Range
select * from product where pid not in(1,2,6,7);
select * from product where pid not between 2 and 5; Inquire about like
Sort query
# Environmental preparation
# Create student table ( Yes sid, The student's name , Student gender , Student age , Fractional column , among sid Auto grow for primary key )
CREATE TABLE student(
sid INT PRIMARY KEY auto_increment,
sname VARCHAR(40),
sex VARCHAR(10),
age INT,
score DOUBLE
);
INSERT INTO student VALUES(null,'zs',' male ',18,98.5);
INSERT INTO student VALUES(null,'ls',' Woman ',18,96.5);
INSERT INTO student VALUES(null,'ww',' male ',15,50.5);
INSERT INTO student VALUES(null,'zl',' Woman ',20,98.5);
INSERT INTO student VALUES(null,'tq',' male ',18,60.5);
INSERT INTO student VALUES(null,'wb',' male ',38,98.5);
INSERT INTO student VALUES(null,' Xiao Li ',' male ',18,100);
INSERT INTO student VALUES(null,' Xiaohong ',' Woman ',28,28);
INSERT INTO student VALUES(null,' cockroach ',' male ',21,95);
select * from student;
# Sort query
select * from student order by score asc;
Aggregate functions
# Aggregate functions
# Find out score minimum value
select min(score) from student;
# Find out score Maximum
select max(score) from student;
# Find out score The sum of the
select sum(score) from student;
# Find the average
select avg(score) from student;
# Calculate the number of records
select count(*) from student;
Aggregate functions do not consider null
边栏推荐
- build. Gradle configuration
- 手把手带你入门 API 开发
- Topic38——56. Consolidation interval
- In 2021, the global enhanced oil production surfactant revenue was about USD 202.3 million, and it is expected to reach USD 297.1 million in 2028
- Object serialization
- 自定义多线程基类threading.Event
- Go Web 编程入门:验证器
- Deep understanding of happens before principle
- 盘点一些好用且小众的 Markdown 编辑器
- MySQL learning 1: installing MySQL
猜你喜欢

秒云荣获《2022爱分析 · IT运维厂商全景报告》智能运维AIOps市场代表厂商

JMETER连接DM8

数据库系列:MySQL索引优化与性能提升总结(综合版)

Dm8: Dameng database - lock timeout

树莓派 3b+ 学习

Picocli getting started

MySQL高阶语句(一)

MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)

56. Core principle of flutter - flutter startup process and rendering pipeline

解除百度文库VIP、语雀、知乎付费限制,原来这么简单
随机推荐
微服务拆分
Topic38——56. 合并区间
行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
全球最强截图软件 Snipaste
Dynamic programming [III] (interval DP) stone merging
Tidb 6.0: making Tso more efficient tidb Book rush
threejs的环境光+点光源+平行光源+球面光 以及hepler理解+阴影()
深入理解 happens-before 原则
MapReduce principle analysis (in-depth source code)
【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(二)
Hands on API development
Nifi from introduction to practice (nanny level tutorial) - identity authentication
Getting started with go web programming: validators
浅谈珂朵莉树
Configuration of YML
LeetCode_ Fast power_ Recursion_ Medium_ 50.Pow(x, n)
yml的配置
Uni app develops wechat applet to dynamically render pages and dynamically change the order of page component modules
alibaba jarslink
Mathematical knowledge -- ideas and examples of game theory (bash game, Nim game, wizov game)