標籤:
1. SQL SERVER Install
可以免費試用180天。最新的是2014版本。
2. Attach, Detach 可以添加或去掉已有的資料庫檔案。 資料庫檔案的格式是: .mdf 尾碼
3. 用戶端上可以建立 E-R圖。主要注意主外鍵關係,一個表的外鍵是另一個表的主鍵。
4. T-SQL Study eg1: order by no. 例如: select ProductID, Name, ProductNumber,Color, Size, ListPrice from Production.Product order by 2 說明: 這裡的2,就是說按“Name” 進行排序。按Select後的 第幾個column進行排序。 eg2: IsNull 函數: 判斷類比一資料是否為空白。
例如: select ProductID, Name, ProductNumber, IsNull(Color, ‘‘), IsNull(Size, ‘‘), ListPrice
from Production.Product order by 2 eg3: as 關鍵字:給表列取別名。
例如: select ProductID, Name, ProductNumber, IsNull(Color, ‘‘) as Color, IsNull(Size, ‘‘) as Size, ListPrice
from Production.Product order by 2 eg4: wildcard: 萬用字元 例如: select * from Production.Product where name like ‘%Mountain%‘ ----Wildcard % matches any zero or more characters select * from Production.Product
where name like ‘_ountain%‘ eg5: in ; not in 例如: select * from Production.Product where size in (‘20‘, ‘50‘,‘55‘) select * from Production.Product where size not in (‘20‘, ‘50‘,‘55‘) eg6: is null ; is not null 例如: select * from Production.Product where size is null select * from Production.Product where size is not null eg6: and ; or 例如: select * from Production.Product where color = ‘red‘ and color = ‘black‘ select * from Production.Product where color = ‘red‘ or color = ‘black‘
5. 彙總函式 eg1: count ; distinct 例如: select count(SalesPersonID)
from [Sales].[SalesOrderHeader] where SalesPersonID is not null select distinct(SalesPersonID) from [Sales].[SalesOrderHeader] where SalesPersonID is not null select count(distinct(SalesPersonID)) from [Sales].[SalesOrderHeader] where SalesPersonID is not null eg2: Avg, Min, Max,Sum 例如: select Avg(SalesPersonID) as AverageTotalSales , Min(SalesPersonID) as MinimumTotalSales , Max(SalesPersonID) as MaximumTotalSales , Sum(SalesPersonID) as SummaryTotalSales from [Sales].[SalesOrderHeader] eg3:
The classical T-SQL query !!! 例如: select SalesPersonID, OrderDate, Max(TotalDue) as MaximumTotalSales from [Sales].[SalesOrderHeader] where SalesPersonID is not null and OrderDate > ‘2016/1/1‘ group by SalesPersonID, OrderDate having Max(TotalDue) > 150000 order by SalesPersonID desc
6. 小技巧 eg1: 如何顯示Line Number? 解決方案: 在SS Management Studio 最上面一行 ribbon 裡面找到 Tool --> Options eg2: 如何自由轉換 queries 大小寫? 解決方案: 在SS Management Studio 最上面一行 ribbon 裡面找到 Edit --> Advanced --> Make UpperCase / LowerCase
SQL SERVER Study