SQL Server 2005新功能有哪些?
以下的文章主要向大家講述的是SQL Server 2005新功能的品味,SQL Server 2005數(shù)據(jù)庫相對(duì)于2000其在很多方面有很大的改進(jìn),有些在實(shí)際操作中還是非常實(shí)用的。舉幾個(gè)例子來簡(jiǎn)單說明 這些例子我引用了PB2K庫。
1. TOP 表達(dá)式
SQL Server 2000的TOP是個(gè)固定值,是不是覺得不爽,現(xiàn)在改進(jìn)了。
前n名的訂單
- declare @n int
- set @n=10
- select top(@n) * from student
2. 分頁
不知各位過去用SQL Server 2000是怎么分頁的,大多都用到了臨時(shí)表。SQL Server 2005一句話就支持分頁,性能據(jù)說也非常不錯(cuò)。
按age從小到大排序,求1到10行的結(jié)果
- select * from (select pid,sname,row_number() over(order by age) as row from student) as temp where row between 1 and 10
3. 排名
- select * from(select pid, title,score, RANK() OVER(order by score desc) as rank from material where score is not null) as temp where rank between 1 and 4
4. try ... catch
SQL Server 2000沒有異常,T-SQL必須逐行檢查錯(cuò)誤代碼,對(duì)于習(xí)慣了try catch程序員,2005是不是更加親切:
SET XACT_ABORT ON -- 打開 try功能
- BEGIN TRY
- begin tran
- insert into student(sname,age) values('test',22)
- commit tran
- print 'commited'
- END TRY
- BEGIN CATCH
- rollback
- print 'rolled back'
- END CATCH
5. 通用表達(dá)式CTE
通過表達(dá)式可免除你過去創(chuàng)建臨時(shí)表的麻煩。
上述的相關(guān)內(nèi)容就是對(duì)SQL Server 2005新功能的描述,希望會(huì)給你帶來一些幫助在此方面。
【編輯推薦】