1、SQL DML 和 DDL數據庫
能夠把 SQL 分爲兩個部分:數據操做語言 (DML) 和 數據定義語言 (DDL)。spa
SQL (結構化查詢語言)是用於執行查詢的語法。可是 SQL 語言也包含用於更新、插入和刪除記錄的語法。code
查詢和更新指令構成了 SQL 的 DML 部分:blog
SQL 的數據定義語言 (DDL) 部分使咱們有能力建立或刪除表格。咱們也能夠定義索引(鍵),規定表之間的連接,以及施加表間的約束。索引
SQL 中最重要的 DDL 語句:table
2、基本語法class
一、distinctselect
--1、查詢A表中姓名不一樣的數據 select distinct name from A --二、查詢A表中(name,id)不一樣的數據,根據「name+id」來去重,distinct同時做用在了name和id上 select distinct name, id from A --3、統計 --表中name去重後的數目 select count(distinct name) from A; --SQL Server不支持如下這種方式 select count(distinct name, id) from A; --4、如下方式會提示錯誤,由於distinct必須放在開頭 select id, distinct name from A;
二、ORDER BY
搜索
select * from student order by sex asc,age desc;
三、top語法
--SQL Server 的語法: SELECT TOP number|percent column_name(s) FROM table_name --查詢前10條數據 select top 10 * from student; --查詢前10%的數據 select top 10 percent * from student;