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.