当前位置:网站首页>Most commonly used SQL statements
Most commonly used SQL statements
2022-06-25 15:52:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
grammar :
Step by step from shallow to deep , It's all used here mysql It's done .
Basics :
Connect to database :
mysql -h10.20.66.32 -uroot -p123456
-h And then mysqlServer Address ,-u Followed by the user name ,-p And then there's the code .
view the database
show databases;
Using a database
use test;
- See the table
show tables;
View table structure
desc winton
Build table
create table t1( id int not null primary key, name char(20) not null );
grammar create table The name of the table ( Field name Field name type Field descriptors , Field name Field type Field descriptors );
Delete table
drop table test;
- 1
grammar :drop table The name of the table ;
Modify table
Add fields
alter table t1 add(score int not null);
grammar :alter table Demonstrative scale add( Field name type The descriptor );
Remove field
alter table t1 drop column score;
grammar :alter table Table name drop colunm Field name ,drop colunm Field name ;
Change field
alter table t1 change name score int not null;
grammar :alter table Table name change Old field name new field name New field descriptor
Insert
Full field insertion
insert into winton values(001,'zww'),(002,'rs');
grammar :insert into Table name values( Field 1 value , Field 2 value ,……),( Field 1 value , Field 2 value ,……);
Insert individual fields
insert into winton(id) values(004);
View the inserted results , As shown in the figure above .
grammar :insert inton Table name ( Field name ) values( It's worth one ),( It's worth two );
Common query
Single table full field query
select * from t1;
grammar :select * from Table name ;
Query individual fields in a single table
select id from t1;
grammar :select Field one , Field 2 from Table name ;
Multi-table query
select t1.id,t1.score,winton.name from t1,winton;
grammar :select Table 1 field , Table II fields , Table III fields ,…… from Table 1 , Table two , Table 3 ,……
Conditions of the query
Single table condition query
select * from t1 where socre>90;
grammar :select Field 1, Field 2 from Table name where Conditions ;
Multi table conditional query
select t1.id,t1.score,winton.name from t1,winton where t1.id=winton.id;
grammar :select Table 1 field , Table II fields from Table 1 , Table two where Conditions ;
nested queries
select name from winton where id=(select id from t1 where score=90);
grammar :select Field one , Field 2 …… from Table name where Conditions ( Inquire about );
And query
(select id from t1 )union(select id from winton);
I'd like to make an inquiry
select id from t1 where id in (select id from winton);
Delete
delete from winton where id=4;
grammar :delete from Table name where Conditions ;
to update
update t1 set score=69 where id=2;
grammar :update Table name set Changed field name = value where Conditions ;
Common functions
Sum up
select sum(score) from t1;
notes :sum( Field ) Invalid for string and time
averaging
select avg(score) from t1;
notes :avg( Field ) Invalid for string and time
Count
select count(*) from t1;
notes :count( Field name ) It doesn't contain NULL;
For maximum
select max(name) from winton;
notes :max(colunm) Returns the highest alphabetical order , Returns the highest value
For the minimum
select min(name) from winton;
notes :min(colunm) Returns the lowest value in alphabetical order , Returns the minimum value of the value
Common modifiers
distinct The value in the field is unique
select distinct name from winton;
limit The number of query results is limited
select * from winton limit 2;
order by Sort
select * from winton order by name;
notes : The default is ascending
desc Descending
slelect * from winton order by name desc;
asc Ascending
select * from winton order by name asc;
group by grouping
select name from winton group by name;
Indexes
Create a normal index
create index wintonIndex on winton (name);
grammar :create index The index name on Table name ( Field one , Field 2 ,……);
Create unique index
create unique index wintonIndex on winton (id);
grammar :create unique index Index name on Table name ( Field one , Field 2 ,……); ps:unique index The data in the column is required to be unique , No repetition .
Remove index
drop index wintonIndex on winton;
grammar : drop index Index name on Table name ;
ending
Okay , Basically, what you can remember is worth so much , Are the most basic , Some of the most commonly used .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/152099.html Link to the original text :https://javaforall.cn
边栏推荐
- Free books! AI across the Internet paints old photos. Here is a detailed tutorial!
- 不要小看了积分商城,它的作用可以很大!
- Take you to the open source project of smart home: the preliminary configuration of zhiting home cloud and home assistant+ homebridge
- Open the box to experience rust, come on!!!
- 什么是NFT数字藏品?
- 李飞飞团队将ViT用在机器人身上,规划推理最高提速512倍,还cue了何恺明的MAE
- 到底要不要去外包公司?这篇带你全面了解外包那些坑!
- 地理位置数据存储方案——Redis GEO
- Sword finger offer 10- I. Fibonacci sequence
- QC, QA, IPQC, JQE, DQA, SQE, DQC, MQC, IQC, FQC, OQC
猜你喜欢
After the project is pushed to the remote warehouse, Baota webhook automatically publishes it
商城风格也可以很多变,DIY了解一下!
剑指 Offer 06. 从尾到头打印链表
Consumer and producer cases of inter thread synchronization (condition variable)
Do you want to go to an outsourcing company? This article will give you a comprehensive understanding of outsourcing pits!
程序员 VS 黑客的思维 | 每日趣闻
基于深度Q学习的雅达利打砖块游戏博弈
Startup and shutdown of appium service
B站付费视频使up主掉粉过万
Day01: learning notes
随机推荐
通俗讲跨域
Jz-065 path in matrix
Startup and shutdown of appium service
MySQL performance optimization - index optimization
Analysis of the concept of metacosmic system
剑指 Offer 09. 用两个栈实现队列
Sword finger offer 06 Print linked list from end to end
教务系统开发(PHP+MySQL)
剑指 Offer 04. 二维数组中的查找
Golang open source streaming media audio and video network transmission service -lal
Open the box to experience rust, come on!!!
How to reload the win10 app store?
LeCun预言AGI:大模型和强化学习都是斜道!我的「世界模型」才是新路
Inter thread synchronization semaphore control
SQL最常用的语句
TFIDF与BM25
Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
Describe your understanding of the evolution process and internal structure of the method area
Sword finger offer 07 Rebuild binary tree
Power representation in go language