当前位置:网站首页>[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;
/*******************************************************/
边栏推荐
- To SystemC Beginners: the first program
- Player practice 19 xaudio turn on audio
- After reading the question, you will point to offer 16 Integer power of numeric value
- English learning plan
- Details of bypassing safeseh mechanism by using modules that do not enable safeseh
- Implementation of Ackermann function with simulated recursion
- Lua common built-in functions
- CSDN blog points rule
- [advanced MySQL] evolution of MySQL index data structure (IV)
- NotePad 常用设置
猜你喜欢
阿里云开发板HaaS510将串口获取数据发送到物联网平台
Player practice 26 adding slider and window maximization
[video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day
Leetcode 2185. 统计包含给定前缀的字符串
Player practice 15 xdemux and avcodecparameters
Socket model of punctual atom stm32f429 core board
chapter19 Allocation
Create a small root heap and judge the node relationship (also.C\u str() substr(),atoi(),string. Use of find())
Design of PLC intelligent slave station based on PROFIBUS DP protocol
Postgresql14 installation and use tutorial
随机推荐
Leetcode 2185. 统计包含给定前缀的字符串
Alibaba cloud development board haas510 sends the serial port data to the Internet of things platform
How to use Android studio to create an Alibaba cloud Internet of things app
Tcp/ip network communication knowledge record
对于跨境电商,更侧重收入的出价策略 —Google SEM
2000. reverse word prefix
IAT hook hijacking process API call
My resume.
Tool notes - common custom tool classes (regular, random, etc.)
Redis data deletion policy in 2022
阿里云开发板HaaS510报送设备属性
Llvm pass-- virtual function protection
Des File Encryptor based on MFC framework
After reading the question, you will point to offer 16 Integer power of numeric value
浅谈中国程序员为什么要跳槽?
Player practice 11 audio resampling
Cmake basic tutorial - 01 a-hello-cmake
Is Shell Scripting really a big technology?
TestEngine with ID ‘junit-vintage‘ failed to discover tests
拆改廣告機---業餘解壓