Demo on debugging simple stored procedure :
Step 1: Create table persons and insert one record
create table persons(pid int primary key,firstname varchar(50),lastname varchar(50))
insert into persons values(1,'basha','shaik')
Step 2 : Create stored procedure
create procedure personsupdate(@Oldfirstname varchar(50),@Newfirstname varchar(50),@Oldlastname varchar(50),@Newlastname varchar(50))
as
begin
declare @pid int
select @pid= pid from persons where firstname=@Oldfirstname and lastname=@Oldlastname
select @pid+=1
update persons set firstname=@Newfirstname,lastname=@Newlastname where pid=@pid
return @@Rowcount
end
Step 3 : Sql statements to call stored proc
GO
-- Put Break point here ( Press F9 after placing cursor at the below statement)
declare @oldlastname varchar(50),@newlastname varchar(50),@oldfirstname varchar(50),@newfirstname varchar(50)
select @newlastname='SHAIK_NEW',@oldlastname='SHAIK',@newfirstname='BASHA_NEW',@oldfirstname='Basha'
DECLARE @RES INT
EXEC @RES=dbo.personsupdate @OLDFIRSTNAME,@newfirstname,@oldlastname,@newlastname
IF @RES=0
BEGIN
PRINT 'FAIL'
END
ELSE
BEGIN
PRINT 'SUCCESS'
END
Step 4 : In Sql server management studio , Go to Debug menu and click on Start debugging (Alt + F5)
Observe locals in the down left side window for variable values and keep press F11 to debug the statements.
Short cut keys for debug -
F11 - Step Into
F10 - Step Over
F9 - Put Break point at specified statement.
Step 1: Create table persons and insert one record
create table persons(pid int primary key,firstname varchar(50),lastname varchar(50))
insert into persons values(1,'basha','shaik')
Step 2 : Create stored procedure
create procedure personsupdate(@Oldfirstname varchar(50),@Newfirstname varchar(50),@Oldlastname varchar(50),@Newlastname varchar(50))
as
begin
declare @pid int
select @pid= pid from persons where firstname=@Oldfirstname and lastname=@Oldlastname
select @pid+=1
update persons set firstname=@Newfirstname,lastname=@Newlastname where pid=@pid
return @@Rowcount
end
Step 3 : Sql statements to call stored proc
GO
-- Put Break point here ( Press F9 after placing cursor at the below statement)
declare @oldlastname varchar(50),@newlastname varchar(50),@oldfirstname varchar(50),@newfirstname varchar(50)
select @newlastname='SHAIK_NEW',@oldlastname='SHAIK',@newfirstname='BASHA_NEW',@oldfirstname='Basha'
DECLARE @RES INT
EXEC @RES=dbo.personsupdate @OLDFIRSTNAME,@newfirstname,@oldlastname,@newlastname
IF @RES=0
BEGIN
PRINT 'FAIL'
END
ELSE
BEGIN
PRINT 'SUCCESS'
END
Step 4 : In Sql server management studio , Go to Debug menu and click on Start debugging (Alt + F5)
Observe locals in the down left side window for variable values and keep press F11 to debug the statements.
Short cut keys for debug -
F11 - Step Into
F10 - Step Over
F9 - Put Break point at specified statement.

No comments:
Post a Comment