当前位置:网站首页>SQL quick query

SQL quick query

2020-11-08 16:57:00 Irving the procedural ape

1、 explain : Create database CREATE DATABASE database-name2、 explain : Delete database drop database dbname3、 explain : Backup sql server--- establish Backup data deviceUSE masterEXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'--- Start Backup BACKUP DATABASE pubs T
  • relational database , Based on the relational model , Use relationship ( surface ) Store the data , At the same time, the integrity constraint is defined . Common relational database systems include :Oracle、MySQL/MariaDB、SQL Server、PostgreSQL wait .
  • SQL, Structured query language , Standard language for accessing and manipulating relational databases .SQL It's declarative , Is a set oriented programming language .

1、 Single table query

SELECT col1, col2 AS c2 --  Column alias  FROM t; --  The basic query SELECT * FROM t; --  Query all fields SELECT col1, col2, … FROM t WHERE conditions; --  Filter conditions SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC; --  Sort SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC OFFSET m ROWS FETCH FIRST n ROWS ONLY; --  Limit the number of  LIMIT n OFFSET m; --  Non standard implementation SELECT col1, col2, agg_fun() --  Aggregate functions  FROM t GROUP BY col1, col2 --  Group summary  HAVING conditions; --  Filter after grouping 

2、 Multiple table joins

SELECT t1.col1, t2.col2, … FROM t1 INNER JOIN t2 ON conditions; --  Internal connection  SELECT t1.col1, t2.col2, … FROM t1 LEFT JOIN t2 ON conditions; --  Left connection SELECT t1.col1, t2.col2, … FROM t1 RIGHT JOIN t2 ON conditions; --  The right connection SELECT t1.col1, t2.col2, … FROM t1 FULL JOIN t2 ON conditions; --  Full connection SELECT t1.col1, t2.col2, … FROM t1 CROSS JOIN t2 ON conditions;--  Cross connect SELECT a.col1, b.col2, … FROM t1 a --  Table alias  JOIN t1 b ON conditions; --  Self join 

3、 Set operations

SELECT col1, col2, … FROM t1 UNION [ALL]SELECT c1, c2, … FROM t2; -.........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢