SQL Server 2005新功能有哪些?
以下的文章主要向大家講述的是SQL Server 2005新功能的品味,SQL Server 2005數據庫相對于2000其在很多方面有很大的改進,有些在實際操作中還是非常實用的。舉幾個例子來簡單說明 這些例子我引用了PB2K庫。
1. TOP 表達式
SQL Server 2000的TOP是個固定值,是不是覺得不爽,現(xiàn)在改進了。
前n名的訂單
- declare @n int
- set @n=10
- select top(@n) * from student
2. 分頁
不知各位過去用SQL Server 2000是怎么分頁的,大多都用到了臨時表。SQL Server 2005一句話就支持分頁,性能據說也非常不錯。
按age從小到大排序,求1到10行的結果
- 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必須逐行檢查錯誤代碼,對于習慣了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. 通用表達式CTE
通過表達式可免除你過去創(chuàng)建臨時表的麻煩。
上述的相關內容就是對SQL Server 2005新功能的描述,希望會給你帶來一些幫助在此方面。
【編輯推薦】