当前位置:网站首页>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 wintonBuild 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
边栏推荐
- Interviewer: your resume says you are proficient in mysql, so you say cluster / Union / overlay index, table return, index push down
- TFIDF与BM25
- How GC determines whether an object can be recycled
- Day01: learning notes
- Brief object memory layout
- MySQL installation tutorial
- 什么是oa
- 说下你对方法区演变过程和内部结构的理解
- Practice of geospatial data in Nepal graph
- Cloning and importing DOM nodes
猜你喜欢

Resolve Visio and office365 installation compatibility issues

《睡眠公式》:怎么治睡不好?

免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!

Brief introduction to class loading process

揭秘GaussDB(for Redis):全面对比Codis

Day01: learning notes

剑指 Offer 09. 用两个栈实现队列

面试官:你简历上说精通mysql,那你说下聚簇/联合/覆盖索引、回表、索引下推

到底要不要去外包公司?这篇带你全面了解外包那些坑!

教务系统开发(PHP+MySQL)
随机推荐
剑指 Offer 05. 替换空格
What are the reasons why the game industry needs high defense servers?
商城风格也可以很多变,DIY 了解一下!
Reflection - learning notes
什么是oa
不要再「外包」AI 模型了!最新研究发现:有些破坏机器学习模型安全的「后门」无法被检测到
Talk about the creation process of JVM objects
Leetcode topic [array]-34- find the first and last positions of elements in a sorted array
Practice of geospatial data in Nepal graph
Startup and shutdown of appium service
中国高校首次!全球唯一!同济学子斩获国际大奖
Describe your understanding of the evolution process and internal structure of the method area
Rapport de la main - d'oeuvre du Conseil de développement de l'aecg air32f103cbt6
转换Cifar10数据集
golang正则regexp包使用-05-扩展Expand()、根据正则切割Split()
不要小看了积分商城,它的作用可以很大!
Is it safe to open a stock account in Guoxin golden sun?
剑指 Offer 10- I. 斐波那契数列
js 给元素添加自定义属性
程序员 VS 黑客的思维 | 每日趣闻