首页 > 数据库技术 > 详细

SqlServer--数据检索(查询)

时间:2016-12-16 01:00:08      阅读:259      评论:0      收藏:0      [点我收藏+]

 

use  MyDataBase1

-- * 表示显示所有列

-- 查询语句没有加where条件表示查询所有行

select *from TblStudent

---只查询表中的部分列

select tsid,tsname,tsgender from TblStudent

--根据条件,只查询部分行(使用where条件筛选部分行显示)

select * from TblStudent where tsclassId=5

--为查询结果集中的列起别名

select tsid as 学生编号,tsname as 学生姓名,tsgender as 性别 from TblStudent

--也可以这样排列

select

tsid as 学生编号,

tsname as 学生姓名,

tsgender as 性别

from TblStudent

 

select

tsid ‘(学生 编号)‘, --可以输出空格

tsname 学生 姓名, --不能输出空格

tsgender 性别

from TblStudent

 

select

学生编号=tsid,

学生姓名=tsname,

性别=tsgender

from TblStudent

 

 

select

学生编号=tsid,

学生姓名=tsname,

性别=tsgender,

婚否=‘否‘

from TblStudent

 

--并不是说select必须配合from一起来使用,可以单独使用select

select

当前系统时间=getdate()

 

select

班长=‘严蒙‘,

班花=‘待定‘,

班草=‘待定‘,

班主任=‘宋词‘

 

--distinct关键字,针对已经查询出的结果然后去除重复

select distinct * from TblStudent

select distinct tsname,tsgender,tsaddress from TblStudent

 

SqlServer--数据检索(查询)

原文:http://www.cnblogs.com/hao-1234-1234/p/6185223.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!