1.把某个字段重新生气序列(从1到n):declare @i intset @i = 0update table1 set @i = @i + 1,field1 = @i2.按成绩排名次update 成绩表set a.名次 = (select count(*) + 1from 成绩表 bwhere a.总成绩 < b.总成绩)from 成绩表 a3.查询外部数据库select a.*from openrowset(microsoft.jet.oledb.4.0,c:\test.mdb;admin;,table1) a4.查询excel文件select * from opendatasource(microsoft.jet.oledb.4.0,data source="c:\test.xls";user id=admin;password=;extended properties=excel 8.0)…sheet1$5.在查询中指定排序规则select * from table1 order by field1 collate chinese_prc_bin为什么要指定排序规则呢?参见:http://www.delphibbs.com/delphibbs/dispq.asp?lid=1633985例,检查数据库中的pub_users表中是否存在指定的用户:select count(*) from pub_users where [username]=admin and [password]=aaa collate chinese_prc_bin默认比较是不区分大小写的,如果不加collate chinese_prc_bin,那么密码aaa与aaa是等效的,这当然与实际不符.注意的是,每个条件都要指定排序规则,上例中用户名就不区分大小写.6.order by的一个小技巧order by可以指定列序而不用指定列名,在下面的例子里说明它的用处(注意,第三列未指定别名)select a.id,a.name,(select count(*) from tableb b where a.id=b.pid) from tablea a order by 3
SQLServer的几个技巧-数据库专栏,SQL Server
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » SQLServer的几个技巧-数据库专栏,SQL Server
相关推荐
- 暂无文章
