How to quickly fix SQL statement errors in SQL Server

Source: Internet
Author: User
Tags sql error sql server management

This article will discuss with you some questions about finding a SQL error.

Now the system is basically need to use the database, since the use of the database we will write SQL script, the common practice is now Microsoft SQL Server Management Sudio write good debugging, and then paste into

Code, but does this guarantee that our SQL scripts will work? What if there is a problem with the SQL or stored procedure with parameters? If there is a problem with the data, how do we find the wrong SQL?

With this question, let's start our discussion today. Before using code and database to deal with data problems, we will make a breakpoint step-by-step debugging, like this:

Find the SQL that may be wrong first, step by step debugging

Until the statement is found and then pasted into the database to execute:

It seems that this approach does solve most situations, but what about stored procedures with parameters, which is one of the reasons most programmers do not love storage (debugging laborious).

In fact, Microsoft has given me a very useful tracking debugging tools SQL Server Profiler (Event Viewer), this tool can track the changes in the database all the way, of course, SQL, storage is not a problem.

To continue with our simple SQL debugging, look at the state in SQL Server Profiler:

is not the same as the SQL result we just debugged in the code.

Debugging storage is one of the most important purposes for which we use it, and below we demonstrate the debugging process with parameter stored procedures:

So we are not very clear to see our database script, even if the parameter is not right we can see the same.

The results of the implementation are as follows:

If you want to use a store to achieve the effect of the red circle (alphanumeric combination and increment by number), please refer to the

SQL Server primary key consists of alphanumeric and automatically grows according to numbers

With Event Viewer, afraid of not finding SQL errors, would you be happy to write a debug store with it?

As many people do not know that there is such a tool exists, the author has done some simple introduction, if Help to you, do not forget to recommend.

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.