当前位置:网站首页>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
边栏推荐
- 想学好C语言,操作符也很重要
- build. Gradle configuration
- Word text box page feed
- 全球最快下载工具 XDM
- uniapp下拉弹层选择框效果demo(整理)
- This privatized deployed enterprise knowledge base makes telecommuting a zero distance
- Microservice splitting
- Nifi from introduction to practice (nanny level tutorial) - identity authentication
- 解除百度文库VIP、语雀、知乎付费限制,原来这么简单
- 如何修改 node_modules 里的文件
猜你喜欢

pull request

面试突击60:什么情况会导致 MySQL 索引失效?

Topic37——64. 最小路径和

【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(二)

MySQL高阶语句(一)

This privatized deployed enterprise knowledge base makes telecommuting a zero distance

Topic37——64. Minimum path sum

MapReduce principle analysis (in-depth source code)

ssh工作流程及原理

Comment modifier Node Fichiers dans les modules
随机推荐
Use of message queues
[fans' welfare] today, I'd like to introduce a method to collect money for nothing - convertible bonds. I personally verified that each person can earn 1500 yuan a year
Browser cookie to selenium cookie login
application.properties 的配置信息
xxl-job学习梳理
JMeter connection DM8
Uniapp drop-down layer selection box effect demo (sorting)
application. Configuration information of properties
Dynamic programming [III] (interval DP) stone merging
解开C语言的秘密《关键字》(第六期)
Minimum editing distance (linear DP writing method)
C # WPF realizes undo redo function
行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
Unzip log. GZ file
Mybaitis generator details
对象序列化
nifi从入门到实战(保姆级教程)——身份认证
log4j. Detailed configuration of properties
ssh工作流程及原理
全球最快下载工具 XDM