天天看点

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,如需转载请自行联系原作者