How to easily debug T-SQL statements and stored procedures under SQL Server 2008

Source: Internet
Author: User
Tags management studio sql server express

First, review the earlier versions of SQL Server:
Back in the SQL Server 2000 era, the functionality of Query Analyzer was still rudimentary, far less powerful than vs. In the era of SQL Server 2005, features such as code highlighting, SQL optimization, and so on, are stepping up, but you still can't debug SQL statements. A better third-party SQL syntax Editor does not seem perfect enough to cause some people to complain that stored procedures are inconvenient for maintenance, and that they are not used when developing.
Second, SQL Server Express Smart tips to enhance:
This feature is SQL2008 in SQL Server 2005 after the upgrade, we can easily invoke smart hints, and vs consistent: Use the shortcut key CTRL + J.

Is this function the same as vs? After all, they are Microsoft's products.
Third, debug T-SQL statement:
1.Debug ordinary T-SQL statements:
The SQL code is as follows:
Use Northwind Go
DECLARE @i int, @j int,@k int set @i = 1;
Set @j = 2; Set @[email protected] + @j
Select @i; Go
It is very simple to define three variables of type int: I, J, K and simple logical operation of these variables, in management Studio as long as easy to press the F11 key, you can debug the above code block.
Then click F11 Debug or F10 Step-by-step debugging code.

Do you think this dubug scene is similar to vs?
Iv. support for complex stored procedure nesting debug:
You may wonder if, in a large system, code such as stored procedure nesting stored procedures or nested storage functions can occur if the majority of the database logic is a stored procedure implementation.
Does SQL2008 support debug functionality? The answer is yes.
First define a simple stored procedure (using the Northwind database in this article) with the following code:
CREATE procedure sp_getorders @orderID int = null
As if (@orderID is null)
Begin PRINT ' null '
End Else
Begin PRINT ' correct '
End Select * from Orders Whereorderid = @orderID
Go
The stored procedure is called within the following batch, with the following code:
DECLARE @i int, @j int,@k int set @i = 1;
Set @j = 2; Select @[email Protected] + @j
EXEC sp_getorders 10248 Select @i;
Go
F11 SQL Debug for the above code.

When the breakpoint passes through the exec sp_getorders 10248 code, click F11 to enter the sp_getorders stored procedure to make a statement debug.
This lets you debug within a nested stored procedure or function, and now you have to admit that the upgraded SQL2008 is becoming more powerful.

How to easily debug T-SQL statements and stored procedures under SQL Server 2008

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.