开发工具与关键技术:SQL Server 2019 SQL
SQL简介
SQL语言是集DDL、DML和DCL于一体的数据库语言。
SQL语言之DDL:定义数据库
SQL语言之DML:操纵数据库
SQL语言之DCL:数据权限控制
SQL语言主要由以下9个单词引导的操作语句来构成,但每一条语句都能表达复杂的操作请求:
(1)DDL语句引导词:Create、Alter、Drop
模式的定义与删除。包括定义Database、Table、View、Index和完整性约束条件等。
(2)DML语句引导词:Insert、Delete、Update、Select
各种方式的更新与检索操作。
各种复杂条件的检索。如连接查找、模糊查找、分组查找、嵌套查找等。
各种聚集操作。包括求平均、求和等,也包括分组聚集、分组过滤等。
(3)DCL语句引导词:Grant、Revoke
安全性控制:授权和撤销授权。
--select *from Cs.sales.customers;
-- * 匹配所有
select first_name,last_name,city
from sales.customers
order by first_name; --desc 倒序 asc 升序
select first_name,last_name,city
from sales.customers
order by city asc, first_name --多条件查询
;
SELECT first_name,last_name,city
from sales.customers
order by len(first_name) asc; --len 计算字符的个数
select first_name,last_name,city
from sales.customers
order by 3,1;-- == order by city,first_name;
--select top 10 first_name,last_name,city
--top 10 查询前十行数据
select top 10 percent first_name,last_name,city
-- percent % 百分之符号 top 10 percent 前10%
from sales.customers
order by 3,1;
select top 10 with ties product_name,list_price
from production.products
order by 2;
--with ties 用最后一行的数据去查找相同的数据
select product_name,list_price
from production.products
order by 2
offset 0 rows --从第几行开始
fetch next 10 rows only; --查找多少行