Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run stored procedure if it's in a separate schema

I am using SQL Server 2008 R2, and I have created a schema Test and in that schema, I created a stored procedure.

I wanted to run it in the text mode by issuing this query:

EXEC SP_HELPTEXT SCHEMA.SPROC

But while running the above query I get this error:

Incorrect syntax near '.'.

Can someone please help me here to resolve this issue.

like image 749
Vikrant More Avatar asked Jun 15 '12 04:06

Vikrant More


People also ask

Are stored procedures part of the schema?

Stored Procedures and Functions A procedure or function is a schema object that logically groups a set of SQL and other PL/SQL programming language statements together to perform a specific task. Procedures and functions are created in a user's schema and stored in a database for continued use.

Are stored procedures schema bound?

Procedures are schema-bound. If a schema name isn't specified when the procedure is created, the default schema of the user who is creating the procedure is automatically assigned.

Can we execute stored procedure inside another stored procedure?

Here is an example of how to call a stored procedure inside another stored procedure. This is also known as nested stored procedures in SQL Server. Step 1: Create two simple stored procedure to insert some data into two different tables. both accept four parameters to insert the data.


2 Answers

Try this

EXEC SP_HELPTEXT 'SCHEMA.SPROC'
like image 123
Preet Sangha Avatar answered Sep 29 '22 13:09

Preet Sangha


sp_helptext to display the result when sp's or any other tsql binded scripts run without schema, for example:

sp_helptext <nameof sp>

but when you want to run it with schema name as initial then run it into single quotes

sp_helptext 'schma.<nameofsp>

like image 24
himanshu Avatar answered Sep 29 '22 14:09

himanshu