天天看點

SQL Server 2012入門T-SQL基礎篇:(3)select語句和from語句

(1)打開SQL Server Management Studio,點選"建立查詢"并在上下文菜單中選擇"AdventureWorksDW2012"作為首選的資料庫;

<a href="http://blog.51cto.com/attachment/201308/202920159.jpg" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/202937408.jpg" target="_blank"></a>

(2)在建立的查詢中輸入"select * from dbo.DimEmployee",然後點選"F5"或者點選菜單欄中的"!執行";

<a href="http://blog.51cto.com/attachment/201308/204337593.jpg" target="_blank"></a>

(3)可以從結果中看的出來,"select"表示要選擇檢視哪些字段;"*"表示查詢的表中所有的字段,"from"定義了資料的來源哪個表;

(4)我們也可以查詢指定的字段,例如查詢表中的"EmployeeKey","ParentEmployeeKey"

(5)我們也可以用關鍵字"TOP"指定傳回前幾行的結果,

例如,我們傳回前五行,見下圖

<a href="http://blog.51cto.com/attachment/201308/212040233.jpg" target="_blank"></a>

(6)如果表中有重複的資料,而你不想在查詢的結果中不想出現重複的資料,使用"DISTINCT"關鍵字;

<a href="http://blog.51cto.com/attachment/201308/213037722.jpg" target="_blank"></a>

本文轉自 bannerpei 51CTO部落格,原文連結:http://blog.51cto.com/281816327/1275856,如需轉載請自行聯系原作者