這里分為二十二個課時把平時學習到的SqlServer資料庫知識要點在這里一一羅列下來,作為作業中筆記速查,不管是面試還是在專案中對SqlServer資料庫的操作應用,這些知識點都是非常基礎和常用的,有必要把它們匯總記錄、日后備查!話不多說,直接上干貨!
課時(一)登錄資料庫
登錄資料庫的方式:
①Windows身份驗證;
②Sql Server身份驗證

課時(二)備份資料庫

課時(三)資料表的創建
nvachar 存盤型別
遇到作業系統是英文作業系統并且對中文字體的支持不全面時,在SQL Server存盤中文字符為varchar就會出現亂碼(顯示為??),唯一能解決問題的是把資料庫欄位的型別改為nvarchar或 者nchar,
使用nvarchar的另一個非常好處就是在判斷字串的時候可以不需要考慮中英文兩種字符的差別.當然,使用nvarchar存盤英文字符會增大一倍的存盤空間,但是在存盤代價已經很低廉的情況下,優先考慮兼容性會給你帶來更多好處的,
課時(四)創建外鍵關聯
選擇主表的某一列,右鍵點擊“關系”,添加關系,在表和列規范點擊,

設定好主鍵表和外鍵表的關聯ID即可:

課時(五)資料的添加Insert

設定主鍵自增

課時(六)批量插入資料使用UNION


課時(七)洗掉delete和更新update

課時(八)select查詢陳述句

select top 7 * from Student; ##查詢表中的行資料 select top 5 percent * from Student; ##查詢表中的5%的資料
課時(九)like模糊查詢


課時(十)查詢排序

課時(十一)聚合函式的使用



課時(十二)分組查詢



select ShoolID 學校編號, COUNT(*) 學生數量, SUM(Score) 成績總和 FROM student GROUP By SchoolID
課時(十三)分組條件查詢having

課時(十四)連接查詢

課時(十五)UNION聯合查詢


課時(十六)子查詢——單表查詢


舉例:
如查詢山東大學所有的學生資訊:
①最笨的方式實作;
首先查詢到山東大學的編號,然后根據編號查詢出學生資訊;

②連接表方式;

③子查詢;
Select * from student where student.SchoolID = (select SchoolID from School where SchoolName = ‘山東大學’);
課時十七 子查詢——多表子查詢

舉例:
我們要查詢所有學校編號大于山東大學編號的學生資訊,
Select * from student where student.SchoolID > (select SchoolID from School where SchoolName = ‘山東大學’);
課時十八 子查詢——in和not in的使用


課時(十九)子查詢—all和any/some關鍵字的使用




課時(二十)視圖和索引



課時(二十一)變數的使用


注意宣告和使用必須同時執行,

課時(二十二)存盤程序



示例Sql代碼:
create procedure pro_student1 as select * from Student; select * from School; exec pro_student1 go create procedure pro_student2 ( @name varchar(50), @sname varchar ) as select * from Student where Name = @name; select * from School where SchoolName = @sname; exec pro_student2 '王小二', '西南財經大學' go create procedure pro_student3 ( @name varchar(50), @sAge int output ) as select @sAge = Age from Student where Name = @name; declare @outAge int; exec pro_student3 '王小二',@outAge output print @outAge
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/1200.html
標籤:SQL Server
上一篇:常用SQL陳述句
