SQL Server 2005 new features-tsql

Source: Internet
Author: User
Tags end error code expression new features try catch wsdl
Server

SQL Server 2005 is a great improvement relative to SQL Server 2000, and some of it is very practical.

Let me give you a few examples to illustrate these examples I quote the Northwind Library.

1. Top expression
The top of SQL Server 2000 is a fixed value, does not feel good, now improved.

--Order of top N names
DECLARE @n int
Set @n = 10
Select Top (@n) * from Orders

2. Paging
I do not know how you used to use SQL Server 2000 paging, most of the use of temporary tables. SQL Server 20,051 words support paging, and performance is said to be very good.


--by freight from small to large order, 20 to 30 of the results of the line
SELECT * FROM (
Select OrderId, Freight, Row_number () over (order by Freight) as ROW from Orders
) A
where row between 30

3. Ranking


SELECT * FROM (
Select OrderId, Freight, Rank () over (order by Freight) as rank from Orders
) A
where rank between 30

4. Try ... catch
SQL Server 2000 has no exceptions, T-SQL must check the error code line-by-row, and 2005 is not kinder to the accustomed Try Catch programmer:


SET Xact_abort on--Open try function
BEGIN TRY
BEGIN Tran
Insert into Orders (CUSTOMERID) VALUES (-1)
Commit Tran
print ' commited '
End TRY
BEGIN CATCH
Rollback
print ' Rolled back '
End CATCH

5. Common expression CTE
An expression eliminates the hassle of creating a temporary table in the past.
Www.knowsky.com


--Example: paging with a common expression
With Orderfreight as (
Select OrderId, Freight, Row_number () over (order by Freight) as ROW from Orders
)
Select OrderId, Freight from Orderfreight where row between 20
In particular, recursion is supported by an expression.


6. Publish Web Service directly
If you want to turn the store procedure into a Web service, use this. NET, IIS does not need to, through the Windows 2003 HTTP Protocol stack directly release WebService, with this feature requires Windows 2003 SP1

--dataset custordersorders (String CustomerID)
CREATE ENDPOINT Orders_endpoint
state=started
As HTTP (
Path= '/sql/orders ',
authentication= (Integrated),
Ports= (Clear)
)
For SOAP (
WebMethod ' Custordersorders ' (
Name= ' Northwind.dbo.CustOrdersOrders '
),

Wsdl=default,
Database= ' Northwind ',
Namespace= ' http://mysite.org/'
)
The Web service is released, typing http://localhost/sql/orders?wsdl to get the WSDL



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.