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.查詢外部數(shù)據(jù)庫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.在查詢中指定排序規(guī)則select * from table1 order by field1 collate chinese_prc_bin為什么要指定排序規(guī)則呢?參見:http://www.delphibbs.com/delphibbs/dispq.asp?lid=1633985例,檢查數(shù)據(jù)庫中的pub_users表中是否存在指定的用戶:select count(*) from pub_users where [username]='admin' and [password]='aaa' collate chinese_prc_bin默認(rèn)比較是不區(qū)分大小寫的,如果不加collate chinese_prc_bin,那么密碼aaa與aaa是等效的,這當(dāng)然與實際不符.注意的是,每個條件都要指定排序規(guī)則,上例中用戶名就不區(qū)分大小寫.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