当前位置:网站首页>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
边栏推荐
- PHP生成唯一字符串
- The birth of a new integrated memory and computing chip is conducive to the application of artificial intelligence~
- VIM configuration tutorial + source code
- [open source]. Net uses ORM to access Huawei gaussdb database
- 第二章编程练习
- Dev-c++在windows环境下无法debug(调试)的解决方案
- WebGL 水波及焦散(刻蚀)的渲染总结
- Python 列表的11个重要操作
- Elasticsearch 学习一(基础入门).
- IT行业薪资一直遥遥领先!十年后的程序员,是否还是一个高薪职业?
猜你喜欢
随机推荐
性能压测时,并发压力增加,系统响应时间和吞吐量如何变化
Xiaoqingtai officially set foot on the third day of no return
Talking about, check the history of which famous computer viruses, 80% of the people do not know!
Station B STM32 video learning
Learn to record and analyze
区块链周报:数字货币发展写入十四五规划;拜登邀请MIT数字货币计划高级顾问加入总统过渡团队;委内瑞拉推出国营加密交易所
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization
Build simple business monitoring Kanban based on Alibaba cloud log service
Using k3s to create local development cluster
c++ opencv4.3 sift匹配
experiment
腾讯:阿里的大中台虽好,但也不是万能的!
It's just right. It's the ideal state
阿里云的MaxCompute数加(原ODPS)用的怎样?
Liteos message queuing actual combat
构建者模式(Builder pattern)
Learn to record and analyze
Five phases of API life cycle
When to write disk IO after one byte of write file




