Click here to Skip to main content
15,898,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am trying to create a roll back transaction for creating a SP, below the sql query i used.

When i execute am getting bellow error


Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'proc'.
Msg 156, Level 15, State 1, Line 31
Incorrect syntax near the keyword 'proc'.

Please Correct me. It would be great if any one provide me the answer very soon.

Thanks in Advance...



begin tran cproc

begin try

create proc samplep(
@fileid int)
as
begin
end

end try
begin catch
IF @@ERROR <> 0

BEGIN

PRINT 'Errors Found ... Rolling back'

ROLLBACK TRANSACTION cproc

RETURN

END

ELSE

begin

PRINT 'No Errors ... Committing changes'

COMMIT TRANSACTION proc

end



end catch
Posted
Comments
CHill60 2-Jul-13 19:48pm    
If you replace "create proc samplep" with "create PROCEDURE samplep" does the first error go away perhaps? As for the 2nd error, the transaction is called "cproc" not "proc"

I think you can't use Try Catch block for creating stored procedure
 
Share this answer
 
There are too many errors in you query. I have updated the syntax.

SQL
create proc samplep(
@fileid int)
as
begin

 begin tran cproc

begin try
print 'some logic'
end try

begin catch
IF @@ERROR <> 0

BEGIN

    PRINT 'Errors Found ... Rolling back'

    ROLLBACK TRANSACTION cproc

    RETURN

END

ELSE

begin

    PRINT 'No Errors ... Committing changes'

    COMMIT TRANSACTION cproc

end
end catch

end
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900