当前位置:网站首页>[MySQL] basic database operation
[MySQL] basic database operation
2022-06-12 14:16:00 【Speech unrecognized】
1 database Additions and deletions
/*******************************************************/
# increase : Create database
create database if not exists sun character set utf8;
# Delete database
drop database sun_db;
# Change : Using a database
use sun;
# check : Query the database in use Query all databases
show databases ;
select database();
/*******************************************************/
2 Database table Additions and deletions
/*******************************************************/
# increase : Add table create table Table name ( Field data type constraint )
create table cs(
uid int primary key,
name varchar(100) not null ,
age int
);
# Delete : Delete database tables
drop table cs;
# check : Inquire about Database table
show tables ;
desc cs1;
# Change : Modify database table name
rename table cs to cs1;
/*******************************************************/
3 Data table fields : Additions and deletions
/*******************************************************/
# increase : Add fields
alter table cs add `desc` varchar(20);
# Delete : Delete field
alter table cs drop age;
# Change : Modify field name
alter table cs change age ages int;
alter table cs change ages age int not null unique ;
alter table cs change uid uid int auto_increment;
# check : Fields in the query table
desc cs;
/*******************************************************/
4 Data sheet data : Additions and deletions
/*******************************************************/
# increase : Add data
insert into cs (uid, name, `desc`) values (null,' The kid ',' handsome ');
insert into cs values (null,' The kid 1',' frigging awesome ');
insert into cs values (null,' The kid 2','8888'),(null,' The kid 3','8888'),(null,' The kid 4','8888');
insert into cs values (null,' The kid 5','8888'),(null,' The kid 6','8888'),(null,' The kid 7','8888');
# Delete : Delete data
delete from cs where uid=3;
delete from cs; # Be careful : Delete all Do not reset the primary key auto increment
truncate cs; # Be careful : Delete all Reset primary key auto increment
# Change : Modifying data
update cs set `desc`='9999' where uid = 5;
update cs set `desc`='9999'; # Be careful : Without conditions All modified
# Inquire about
select * from product;
select p.pname as " goods ",p.price as " Price " from product as p ;
select pname as " goods ",price as " Price " from product;
# Conditions of the query where
select * from product where price > 300;
select * from product where price >= 300;
select * from product where price < 300;
select * from product where price <= 300;
select * from product where price != 300;
select * from product where price <> 300;
# Logical query and or not
select * from product where price >200 and price<3000;
select * from product where price <200 or price>3000;
select * from product where not (price>200 and price<3000);
# Empty judgment
select * from product where category_id is null;
select * from product where category_id is not null;
# Sort query
select * from product order by price;
select * from product order by price,category_id;
select * from product order by price desc ,category_id desc ;
select * from product order by price asc,category_id asc;
# Fuzzy query between and ,like % _ ,in
select * from product where price between 200 and 3000;
select * from product where price in (200,600);
select * from product where pname like "__ Si ";
select * from product where pname like "% Si %";
select * from product where pname like "% Hegemony %";
select * from product where pname like "___";
# Aggregate query count max min sum avg
select count(*) from product;
select count(*) from product where price>300;
select max(price) from product;
select min(price) from product;
select sum(price) from product;
select avg(price) from product;
select round(avg(price),5) from product;
# Group query group by having Conditions
select category_id from product group by category_id;
select category_id,sum(price) from product group by category_id;
select category_id,sum(price) from product group by category_id having sum(price)>300;
# Paging query limit m,n
select price,pname from product where price>300 order by price desc ;
select price,pname from product where price>300 order by price desc limit 0,3;
/*******************************************************/
边栏推荐
- chapter19 Allocation
- 1414. minimum number of Fibonacci numbers with sum K
- 单总线温度传感器18B20数据上云(阿里云)
- 如何使用android studio制作一个阿里云物联网APP
- 2021-05-28
- CUDA error: CUBLAS_ STATUS_ NOT_ INITIALIZED when calling `cublasCreate(handle)`
- 阿里云开发板HaaS510报送设备属性
- Communication flow analysis
- Socket model of punctual atom stm32f429 core board
- QA of some high frequency problems in oauth2 learning
猜你喜欢

Acwing: topology sequence

Implementation and debug of process hiding under x64

Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?

Program analysis and Optimization - 6 loop optimization

高考回忆录

Is Shell Scripting really a big technology?

What is automatic bidding? What are its advantages?

Alibaba cloud development board haas510 submission device attributes

Socket model of punctual atom stm32f429 core board

阿里云开发板HaaS510解析串口JSON数据并发送属性
随机推荐
【视频课】android studio物联网APP设计制作全套教程--国庆期间全掌握
Player practice 20 audio thread and video thread
Fourteen week assignment
To SystemC Beginners: the first program
Introduction to functions (inline functions and function overloading)
Brush one question every day /537 Complex multiplication
Word insert picture blocked by text
Dynamic search advertising intelligent search for matching keywords
Communication flow analysis
Comparator summary
Design of PLC intelligent slave station based on PROFIBUS DP protocol
Player actual combat 21 audio and video synchronization
阿里云开发板HaaS510响应UART串口指令
Lua common built-in functions
Redis core configuration and advanced data types
Write policy of cache
Conversion of player's actual 10 pixel format and size
肝了一个月的原创小袁个人博客项目开源啦(博客基本功能都有,还包含后台管理)
如何使用android studio制作一个阿里云物联网APP
Mold and remainder