当前位置:网站首页>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
边栏推荐
- In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
- 数据库系列:MySQL索引优化与性能提升总结(综合版)
- MySQL high level statements (I)
- 一个有趣的网络掩码的实验
- 剑指 Offer 04. 二维数组中的查找
- 在 Golang 中构建 CRUD 应用程序
- yml的配置
- Ssh server configuration file sshd_ Config and operation
- Configuration of thymeleaf
- Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
猜你喜欢
随机推荐
Browser cookie to selenium cookie login
动态规划【三】(区间dp)石子合并
Use of message queues
推荐系统的下一步?阿里时空聚合GNN,效果吊打LightGCN!
和动态规划的第一次相遇
Raspberry pie 3b+ learning
Comment modifier Node Fichiers dans les modules
Write it down once Net analysis of a property management background service stuck
面试突击60:什么情况会导致 MySQL 索引失效?
application. Configuration information of properties
全球最强截图软件 Snipaste
Quanzhi A13 tossing memo
二叉树的三种遍历方式
Take stock of some easy-to-use and niche markdown editors
Microservice splitting
esp32s3 IPERF例程测试 esp32s3吞吐量测试
In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
Configuration of YML
build.gradle 配置
[on Nacos] get started quickly