共享学习心得

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

1.compare 直接比较两个字符串,如果不一样,则返回-1

 

2.convert  数据类型转换函数,如:convert(varchar(20),title)

 

3.count 返回非空值的数量或选定的行数。count([all|distinct] expression)

其中distinct是在应用count前取消重复值。

eg:查找作者居住的不同城市的数量:

select count(distinct city) from authors

 

eg:列出titles表中的类型,但取消只包含一本书或不包含任何书的类型:

select type  from titles group by type having count(*)>1

 

count(*)是返回行数,用的最多。

 

4.current_date() 返回当前日期(不包括小时)。

eg: select current_date()

eg: datename标识当前日期

select datename(month,current_date())

结果:August

注意:结果不是8

 

eg:datepart标识当前日期

select datepart(month,current_date())

结果:8

 

5.current_time() 返回当前时间

eg: select current_time()

eg: 返回当前时间的分钟

select datename(minute,current_time())

 

6.curunreservedpas 返回指定磁盘区段中的可用页数

Curunreservedpgs(dbid,istart,unreservedpgs)

dbid是数据库的ID,它们存储在sysdatabasesdbid字段。

Istart是要返回的页所在磁盘区段中的一页。

Unreservedpgs是在dbtable当前对于所请求的数据库不可用时返回的缺省值。

 

eg: 返回数据库名称、设备名和每个设备区段中的未保留页数。

select db_name(dbid),d.name ,curunreservedpgs(dbid,1,unreservedpgs)

from sysusages u ,sysdevices d where d.low <=u.size+vstart

and d.high>=u.size+vstart - 1

and d.status &2 = 2

 

eg:显示从sysusages.istart开始的dbid段上的可用页数;

select curunreservedpgs(dbid, sysusages.istart,0)

实例化:select curunreservedpgs(6,1,0)

posted on 2006-12-04 20:29  神秘狭  阅读(802)  评论(0)    收藏  举报