SQL Server 2005 new features

Source: Internet
Author: User
Tags error code expression sql net new features try catch wsdl
Server for a few examples to simply 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.

--Top N Orders
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.

--Example: paging with a common expression
withOrderfreight 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 ENDPOINTOrders_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

In HTTP communication, the example code uses Windows integration validation.
Give a client example. private void Button1_Click (object sender, EventArgs e)
{
localhost. Orders_endpoint ENDP = new localhost. Orders_endpoint ();
ENDP. Credentials = System.Net.CredentialCache.DefaultCredentials;
Object[] r = ENDP. Custordersorders ("Vinet");

DataSet ds = new DataSet ();
foreach (object o in R)
if (o DataSet) ds = (DataSet) o;

Datagridview1.datasource = ds. Tables[0];
}

SQL Server 2005 supports multiple validations such as Basic, Digest, SQL Auth, and you need to write different validation code.



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.