当前位置:网站首页>SQL 速查
SQL 速查
2020-11-08 16:57:00 【程序猿欧文】
1、说明:创建数据库CREATE DATABASE database-name2、说明:删除数据库drop database dbname3、说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'--- 开始 备份BACKUP DATABASE pubs T
- 关系数据库,基于关系模型,使用关系(表)存储数据,同时定义了完整性约束。常见的关系数据库系统包括:Oracle、MySQL/MariaDB、SQL Server、PostgreSQL 等等。
- SQL,结构化查询语言,访问和操作关系数据库的标准语言。SQL 具有声明性,是一种面向集合的编程语言。
1、单表查询
SELECT col1, col2 AS c2 -- 列别名 FROM t; -- 基本查询SELECT * FROM t; -- 查询所有字段SELECT col1, col2, … FROM t WHERE conditions; -- 过滤条件SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC; -- 排序SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC OFFSET m ROWS FETCH FIRST n ROWS ONLY; -- 限定数量 LIMIT n OFFSET m; -- 非标准实现SELECT col1, col2, agg_fun() -- 聚合函数 FROM t GROUP BY col1, col2 -- 分组汇总 HAVING conditions; -- 分组后过滤
2、多表连接
SELECT t1.col1, t2.col2, … FROM t1 INNER JOIN t2 ON conditions; -- 内连接 SELECT t1.col1, t2.col2, … FROM t1 LEFT JOIN t2 ON conditions; -- 左连接SELECT t1.col1, t2.col2, … FROM t1 RIGHT JOIN t2 ON conditions; -- 右连接SELECT t1.col1, t2.col2, … FROM t1 FULL JOIN t2 ON conditions; -- 全连接SELECT t1.col1, t2.col2, … FROM t1 CROSS JOIN t2 ON conditions;-- 交叉连接SELECT a.col1, b.col2, … FROM t1 a -- 表别名 JOIN t1 b ON conditions; -- 自连接
3、集合运算
SELECT col1, col2, … FROM t1 UNION [ALL]SELECT c1, c2, … FROM t2; -.........
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4708273
边栏推荐
- 第二章编程练习
- LiteOS-消息队列-实战
- I used Python to find out all the people who deleted my wechat and deleted them automatically
- TypeScript(1-2-2)
- Restfulapi learning notes -- father son resources (4)
- Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization
- Design by contract (DBC) and its application in C language
- What is forsage Ethereum smart contract? What is the global decline of Ethereum
- c++ opencv4.3 sift匹配
- 大龄程序员没有出路吗?
猜你喜欢

C + + things: from rice cookers to rockets, C + + is everywhere

契约式设计(Dbc)以及其在C语言中的应用

2020-11-05

read文件一个字节实际会发生多大的磁盘IO?

One minute comprehensive understanding of forsage smart contract global shared Ethereum matrix plan

B站stm32视频学习

Tips and skills of CSP examination

我用 Python 找出了删除我微信的所有人并将他们自动化删除了

awk实现类sql的join操作

Improvement of rate limit for laravel8 update
随机推荐
进入互联网得知道的必备法律法规有哪些?
机械硬盘随机IO慢的超乎你的想象
experiment
趣文分享:C 语言和 C++、C# 的区别在什么地方?
Improvement of maintenance mode of laravel8 update
AI perfume is coming. Will you buy it?
Use markdown
experiment
VIM configuration tutorial + source code
I used Python to find out all the people who deleted my wechat and deleted them automatically
IT行业薪资一直遥遥领先!十年后的程序员,是否还是一个高薪职业?
C + + opencv4.3 sift matching
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
How to cooperate with people in software development? |Daily anecdotes
Improvement of rate limit for laravel8 update
契约式设计(Dbc)以及其在C语言中的应用
Welcome to offer, grade P7, face-to-face sharing, 10000 words long text to take you through the interview process
Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time
B站stm32视频学习
LiteOS-消息队列