当前位置:网站首页>Common SQL statements
Common SQL statements
2022-06-09 22:37:00 【Versatile senior】
Commonly used SQL sentence :
1、 Create database
CREATE DATABASE database-name;
3、 Delete database
DROP DATABASE database-name;
5、 Create new table
create table depart (dept_id int(11) NOT NULL AUTO_INCREMENT,
dept_name varchar(255) DEFAULT NULL, PRIMARY KEY (dept_id));
8、 Create a new table from an existing table :
create table tab_new like tab_old ( Use old table B Create new table A)
10、 remarks : In this way, the table B Copied to the A When will the watch B Copy the complete field structure and index to the table A In the to
create table tab_new as select col1,col2… from tab_old definition only
12、 remarks : In this way, only the table B The field structure of is copied to the table A In the to , But the table will not be copied B Index to table in A In the to . This method is flexible. You can specify which fields to copy while copying the original table structure , You can also add field structure to the self copying table as needed .
create table as select A complete copy of the data in the original table , But the indexes in the table structure will be lost .
create table like Only the table creation statement of the original table will be copied completely , But the data will not be copied .
15、 Delete new table
drop table tabname;
17、 Add a column
alter table tabname add column column_name type
19、 Add primary key : Alter table tabname add primary key(col)
20、 Delete primary key : Alter table tabname drop primary key
21、 A data table can only have one primary key , Therefore, there is no primary key to delete a column .
22、 Create index :create [unique] index idxname on tabname(col….)
23、 Delete index :drop index idxname
24、 notes : The index is immutable , If you want to change it, you must delete and rebuild .
25、 Create view :create view viewname as select statement
26、 Delete view :drop view viewname
27、 A few simple basic sql sentence
28、 choice :select * from table1 where Range
29、 Insert :insert into table1(field1,field2) values(value1,value2)
30、 Delete :delete from table1 where Range
31、 to update :update table1 set field1=value1 where Range
32、 lookup :select * from table1 where field1 like ’%value1%’
33、 Sort :select * from table1 order by field1,field2 [desc]
34、desc: Descending ,asc: Ascending
35、 total :select count as totalcount from table1
36、 Sum up :select sum(field1) as sumvalue from table1
37、 Average :select avg(field1) as avgvalue from table1
38、 Maximum :select max(field1) as maxvalue from table1
39、 Minimum :select min(field1) as minvalue from table1
40、 grouping :Group by:
41、 A watch , Once the grouping is complete , Only group related information can be obtained after query .
42、 Group related information :( Statistics ) count,sum,max,min,avg
43、 Copy table select * into b from a where 1<>1
44、 Subquery ( Table name 1:a Table name 2:b) select a,b,c from a where a IN (select d from b )
45、 Show article 、 The author and the final response time
46、select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
47、 View query ( Table name 1:a )
48、select * from (SELECT a,b,c FROM a) T where t.a > 1;
49、between Usage of ,between The boundary value is included when the query data range is limited ,not between barring
50、select * from table1 where time between time1 and time2
51、select a,b,c, from table1 where a not between The number 1 and The number 2
52、in How to use
53、select * from table1 where a [not] in (‘ value 1’,’ value 2’,’ value 4’,’ value 6’)
54、 Two related tables , Delete the information in the primary table that is not in the secondary table
55、delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
56、 Schedule five minutes in advance to remind
57、SQL: select * from Schedule where datediff(‘minute’,f Starting time ,getdate())>5
58、 front 10 Bar record
59、select top 10 * form table1 where Range
60、 Choose in each group b The data with the same value corresponds to a The biggest record of all information ( Similar usage can be used for forum monthly leaderboards , Monthly hot product analysis , Rank by subject score , wait .)
61、select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)
62、 Including all in TableA But not in TableB and TableC The result table is derived by eliminating all duplicate rows
63、(select a from tableA ) except (select a from tableB) except (select a from tableC)
64、 Random take out 10 Data select top 10 * from tablename order by newid()
边栏推荐
- Actions before purchasing memory modules
- C语言试题163之计算某一天是对应年的第几天,这一年一共多少天;计算两个日期之间相隔的天数。两个日期由键盘输入。
- SDN特有的网络安全问题
- 调查显示macOS应用开发者普遍表示产品如何被用户发现是他们最大的挑战
- St link V2 Download: internal command error & error: flash download failed - target DLL has been canceled
- Diligence from childhood
- 【刷题篇】跳跃游戏
- 时间序列预测中使用类EMD方法时的信息泄露和计算量问题
- 【滤波器】基于时变维纳滤波器实现语音去噪含Matlab源码
- 尽一份孝心,为家人做一个老人防摔报警系统
猜你喜欢

目前28岁,从20年开始北漂闯荡到入职软件测试,我成功捧起15K薪资

Aquanee will land in gate and bitmart in the near future, providing a good opportunity for low-level layout

YUV格式与RGB格式

化工企业双重预防体系数字化综合管理系统
![[image encryption and decryption] image encryption and decryption based on chaotic sequence combined with dwt+svd (including correlation test) including Matlab source code](/img/92/6fa03b5379e4c419328d5ddebe57d4.png)
[image encryption and decryption] image encryption and decryption based on chaotic sequence combined with dwt+svd (including correlation test) including Matlab source code

2022 safety production month activity starts safety production and epidemic prevention and control

汛期建筑施工现场安全生产风险智能防控

从零开始实现lmax-Disruptor队列(二)多消费者、消费者组间消费依赖原理解析

Campus Ruijie router User Guide

Huawei device configuration hub and spoke
随机推荐
Veracrypt create file type encrypted volume
SQL高级处理
浅谈倍增法求解LCA
C language 0 length array (variable array / flexible array) explanation
常见SQL语句
MySQL的集合运算
Find My产品|新款TWS耳机支持Find My功能,苹果Find My在第三方厂家应用更广泛
Find My技术|物联网时代,苹果Find My实现真正的智能防丢
【蓝桥杯集训100题】scratch眩晕苹果 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第12题
从内核代码了解SQL如何解析
On a machine with 4GB of physical memory, how about applying for 8g of memory?
使用sqlplus远程连接ASM实例的方式
[bearing fault decomposition] realize bearing fault signal decomposition based on ITD, including Matlab source code
M-Arch(雅特力M4)【AT-START-F425测评】No.05 FLASH
这本书押中了2022北京高考作文题
请教个问题,flink-sql,想指定从一个时间点开始读取数据?可以这样搞么?
sparksql源码系列 | 最全的logical plan优化规则整理(spark2.3)
Actions before purchasing memory modules
Digital supervision of construction sites and the wisdom of scientific warfare
lua学习笔记(4)-- 搭建mobdebug 远程开发环境