tailieunhanh - Hướng dẫn học Microsoft SQL Server 2008 part 64
Bạn có chắc chắn''''yêu cầu barkeep?. ''Tất nhiên, trên thực tế, tôi đang tích cực''Lame, tôi biết, nhưng đó là trò đùa geek yêu thích của tôi;. Tôi không thể giúp nó. Trở lại SQL, mặc dù những nỗ lực của chúng tôi tốt nhất, bất kỳ ứng dụng có thể bị mất một electron mỗi một lần trong một thời gian - trick là để xử lý nó một cách tích cực. Tất nhiên, tất cả các ngôn ngữ lập trình mạnh mẽ cung cấp một số phương pháp bẫy, khai thác gỗ, và xử lý các lỗi | T-SQL Error Handling A- - So an atom goes into a bar and says to the barkeeper Hey I think I ve lost an electron. Are you sure asks the barkeep. Of course in fact I m positive. Lame I know but it s my favorite geek joke I couldn t help it. Back to SQL despite our best efforts any application can lose an electron every once in a while the trick is to handle it in a positive way. Of course all robust programming languages provide some method for trapping logging and handling errors. In this area T-SQL has a sad history almost as sad as that joke but it s made significant progress with SQL Server 2005. There are two distinctly different ways to code error handling with SQL Server Legacy error handling is how it s been done since the beginning of SQL Server using @@error to see the error status of the previous SQL statement. Try catch was introduced in SQL Server 2008 bringing SQL Server into the 21st century. IN THIS CHAPTER Legacy error handling Try catch blocks Rethrowing errors Legacy Error Handling Historically T-SQL error handling has been tedious at best. I d prefer to not even include this legacy method of handling errors but I m sure you ll see it in old code so it must be covered. 593 Part IV Developing with SQL Server What s New with Error Handling Unfortunately there is nothing new in 2008 when it comes to error handling. However when performing code reviews for third-party software vendors I rarely see production code with any error handling much less the improved which was introduced in SQL Server 2005. So from an adoption standpoint it may as well be new. The basic error information system functions such as @@error and @@rowcount contain the status for the previous T-SQL command in the code. This means that the legacy method of error handling must examine T-SQL s system functions and handle the error after each SQL statement that might potentially encounter an error. @@error system function The @@error
đang nạp các trang xem trước