Đang chuẩn bị liên kết để tải về tài liệu:
Microsoft SQL Server 2008 R2 Unleashed- P178
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft SQL Server 2008 R2 Unleashed- P178:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major releases.Microsoft SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 1724 CHAPTER 43 Transact-SQL Programming Guidelines Tips and Tricks The following example is similar to the query in Listing 43.58 but replaces CROSS APPLY with the OUTER APPLY clause select st.stor_id stor_name s.ord_date s.qty from stores st outer apply dbo.fn_GetTopOrders st.stor_id 3 as s where st.state MI and st.stor_name in Barnes Noble B Dalton Bookseller Waldenbooks order by stor_id s.qty DESC go stor_id stor_name ord_date qty B251 B Dalton Bookseller 2008-01-23 00 00 00.000 1740 B251 B Dalton Bookseller 2007-11-04 00 00 00.000 1704 B251 B Dalton Bookseller 2008-02-22 00 00 00.000 1560 B510 Barnes Noble 2008-08-13 00 00 00.000 1464 B510 Barnes Noble 2007-10-08 00 00 00.000 1200 B510 Barnes Noble 2006-01-08 00 00 00.000 924 B511 Barnes Noble NULL NULL P963 Waldenbooks 2008-07-07 00 00 00.000 1668 P963 Waldenbooks 2006-12-30 00 00 00.000 1068 P963 Waldenbooks 2006-03-29 00 00 00.000 1032 Q017 Waldenbooks 2007-11-02 00 00 00.000 1776 Q017 Waldenbooks 2006-06-15 00 00 00.000 1704 Q017 Waldenbooks 2007-02-24 00 00 00.000 1548 TRY.CATCH Logic for Error Handling SQL Server 2005 also introduced the TRY.CATCH construct which you can use within T-SQL code to provide a more graceful mechanism for exception handling than was available in previous versions of SQL Server. In versions prior to 2005 error handling was typically done by checking @@ERROR after each SQL statement and often using the GOTO statement to branch to an error-handling routine. A TRY.CATCH construct consists of two parts a TRY block and CATCH block. When an error condition is detected in a T-SQL statement that is inside a TRY block control is immediately passed to the CATCH block where the error is processed. T-SQL statements in the TRY block that follow the statement that generated the error are not executed. If an error occurs and processing is passed to the CATCH block after the statements in the CATCH block are executed control is transferred to the first T-SQL statement that follows the END .