New SQL Stored Procedure not showing in Object Explorer - sql

I am using SQL Server 2005 on a client site. In the past I have created stored procedures in it with no problem. The last stored procedure I created does not show up in Object Explorer under "Stored Procedures". I tried saving it with and w/o dbo.
If I try to save another new stored procedure, the name of the one that is not displayed in Object Explorer appears as an option in the "Save File As" picklist.

It will be added to the bottom of the tree when you execute/add the stored procedure. Refresh the Stored Procedure folder in the tree for it to sort it into alpha order.
Also ensure you are creating the Stored Procedure on the database by executing the code with Create Procedure before the procedure name. If you then need to edit the procedure simple modify (right click the procedure in the explorer tree) and change Create Procedure to Alter Procedure.

Related

Calling an SQL stored procedure from a script in a different directory

I'm trying to call a stored procedure from an sql script. The only issue is the stored procedure is located in a different folder. Is there a way to call the stored procedure from a different directory (or a way to change directories)?

Can I check the dependencies of a stored procedure with other database?

Thank you for reading.
Temp_server
- Temp_db1
. Table : Temp_table
. stored procedure (they refer Temp_table of Temp_db1)
- Temp_db2
. stored procedure (they refer Temp_table of Temp_db1)
Assume that:
there is a server (called Temp_server)
there are two databases (called Temp_db1, Temp_db2)
In Temp_db1, there is a Temp_table and some stored procedures that refer to Temp_table.
In this situation, I can view the list of stored procedure which refer to Temp_table.
But, in SSMS, it shows only the stored procedure of Temp_db1. This means, if there is a stored procedure that is saved on Temp_db2 and refers to Temp_table of Temp_db1, it doesn't show up.
Can I view this, too, somehow?
Can I view this, too, somehow?
You can use sys.sql_expression_dependencies
It shows you dependencies in other databases and even other(linked) servers.
Here is an example when it shows up my historical triggers that writes to another database, Storico.
You can see also test_powershell stored procedure that uses xp_cmdshell from master
and sp_write_execution_log procedure that uses loopback server to execute another sp, sp_write_execution_log_lnk.

Why does the stored procedures not execute the rest of the code?

I have a stored procedure, which was written by another developer whi I have subsequently replaced. At the beginning of their store procedures they delete / drop the table using the following code:
EXEC DBA.usp_DeleteTableByName 'Customer_Import'
It appears though that the above line of the code is the only one, which gets executed as at the rest of the code within this stored procedure performs a SELECT INTO to recreate and populate the Customer_Import table.
Why would the stored procedure stop executing after the above line of code has been successfully executed?

Can't execute stored procedure

I have created a stored procedure and can see it under the stored procedure node, but when trying to execute it doesn't find the procedure.
Under stored procedure node it is called dbo.CopyTable
exec CopyTable
CopyTable is undefined in red saying it does not exist. Why?
Even if I right-click on the procedure and say script stored procedure as execute to - the code it generates is underlined in red and cant find stored procedure either.
Ensure that the database selected contains the stored procedure CopyTable
USE YourDatabase
EXEC CopyTable
Try adding dbo and selecting the right database,
USE databaseName
GO
EXEC dbo.CopyTable
GO
Execute a Stored Procedure
Most likely you are just in the wrong database in the query window, you can specify the database like this:
EXEC [yourDBName].dbo.CopyTable
Reading on how to Execute a Stored Procedure
Considering your updated question:
Even if i rightclick on the procedure and say script stored procedure
as execute to - the code it generates is underlined in red and cant
find stored procedure either.
This could happen if your stored procedure is invalid. Please double-check the validity of the SPROC and ensure the tables it references exist, etc.
Try running your CREATE PROCEDURE. Highlight it, f5 it, and then make sure it runs before you call it elsewhere.
Maybe in your procedure you've accidentally cut-pasted your script name (dbo.CopyTable), say something like...
SELECT * FROM dbo.CopyTable
WHERE ClientId = #ClientId
RETURN
Then when you call your proc you get 'invalid object name dbo.CopyTable' and assume sql is having trouble finding the stored-proc ... which isn't the problem, its finding and running the proc but its actually a problem within the proc.

Create Stored Procedure in Access 2007

Is it possible to create an Stored Procedure in Access 2007? If it is, how can i do it?
Thanks
You could save queries with parameters that works much like a SP.
You can created stored procedures in Access. I use Access 2007. I'm not sure of the capability in Access 2003. I've created stored procedures using the following process:
Create a query that performs the action you wish to take (Create(MakeTable), Read(Select), Update, Delete). Setup parameters if used. This query is for use as a template. You don't need to keep.
Switch query to SQL View and copy the query.
Use Cntl-G to switch over to Visual Basic. Use either the immediate window or create a subroutine using Insert | Procedure.
Paste your query and setup the following syntax to create the stored procedure.
CurrentProject.Connection.Execute "CREATE PROC sp_storedProcedureName (parm1 Text, parm2 Integer, whatever other parms & datatypes) AS sqlStatementFromQueryGoesHere;"
Run from immediate window or procedure. It should run clean if no errors.
Then go back to the Navagation pane and refresh (the stored proc won't show originally without refresh). Once refreshed, you have your stored proc showing in the queries category