I have created a stored procedure in the New Query window. I made sure that my database for the new procedure matches the database for which I created the stored procedure.
I executed the creation of the stored procedure successfully. I then refreshed the window structure and it shows the new created stored procedure (in this case, spGetEmployeesByGenderAndSalary
but when I try to run it in the query window, it doesn't show up in the suggested features.
Not to say it doesn't acknowledge it's existence. If I simply type out
EXEC spGetEmployeesByGenderAndSalary it runs fine
I just don't understand why it doesn't show up in the automated suggestions box.
Update- apparently it appears if I close out SSMS entirely and reboot it, now it shows up fine. Is it always like this, though? Is it some kind of glitch? Anyone else had this issue?
Also, what's this feature called? Intellisense?
Related
I am trying to get some data off a server which I only have read access on using an analytic stored procedure that has not been promoted there yet, so I am using it manually like
CREATE PROCEDURE ###MyProcedure
Then in another query window I can run the new temporary procedure just fine. But soon as I close the query window which has the create statement, the temporary procedure is gone. To make matters worse, there are multiple subroutines that therefore require me to spam my workspace with open query windows to use this approach.
I thought globally-scoped temporary objects were retained until all referencing connections were closed. The only difference in my connection details (using F4 properties tab) between query windows in SSMS is the SPID, but I see the same connection name.
This is a known feature of using local and global stored procedures; that they only exist while the connection exists. Since each query window uses its own connection, the procedures are thus dropped when their defining query windows are closed.
Instead of using CREATE PROC ##YourSP... Try making it persistent in tempdb: CREATE PROC tempdb.dbo.YourSP.... it'll then persist until the SQL Server restarts (as tempdb is rebuilt every time the service is started).
Edit: if you're using using SQL Server 2016+, you could also, instead, use CREATE OR ALTER PROC... This'll stop the CREATE generating an error if the service hasn't yet been restarted; and thus the SP hasn't yet been lost.
In Server Explorer (within Visual Studio) I can expand a database, right click on the Stored Procedures folder, and select "Add New Stored Procedure"
I can then add an SP and try to execute it. However, when I try to save the Stored Procedure (so that it will be subsequently available in the list of Stored Procedures for that database), it gives it the generic name "dbo.Procedure.sql*", even though I gave it another name, such as:
CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]
When the save dialog displays (wanting to save the .sql file to my Documents folder), I can rename it what I want, but it is not available in the list of Stored Procedures in the database.
How can I get it to be available there?
Note: If I right-click the Stored Procedure pane and select "copy path" (or some such), I do get what seems valid, namely:
MSSQL::/PROSQL42/PlatypusData/sa/SqlProcedure/dbo.Procedure.sql
But again, you see the generic "dbo.Procedure.sql" name. Yet no "dbo.Procedure.sql" displays in the list of Stored Procedures after saving, either.
So again, what do I need to do to save my new Stored Procedure into the database I'm working with?
CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]
and the definition that follows is the TSQL which will 'save' it to the database.
If you run that line again, you should get an error saying that it already exists.
To verify that it does, right-click the 'Stored Procedures' node and choose 'Refresh'.
If it doesn't appear in the database you think you're working with, check the connection of the window you're in.
To be sure, add
USE [DatabaseName]
GO
Before executing your CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]
Is there a way to start a stored procedure that has been configured for automatic startup via sp_procoption without having to restart SQL Server?
Occasionally I'll need to make an adjustment and have to KILL the running session to do so, but I cannot seem to locate a way to turn it back on again without restarting SQL Server.
I've tried the most obvious options, like calling the procedure from a query window, but that's not the correct way to go about this as it requires the query to remain open.
I've searched both here and on Google to no avail. I suspect I'm not asking the right question.
Thanks in advance.
I am using MSSQL Management Studio. I have creates a stored procedure using CREATE PROCEDURE and am now working on it with a script that now contains ALTER PROCEDURE. The procedure name following this statement is underlined in red, and the editor says it cannot find it. Nevertheless, the stored procedure appears in the left-hand tree view, and I can right-click it and run it without error. When I do this, the temporary script that is generated to run the stored procedure...
EXEC #return_value = [dbo].[SP_V00_CreateABCTable]
also underlines the name in red.
I don't understand how the editor can claim the object doesn't exist but then runs it without error. Does anyone have any idea what may be going on?
Or you can also refresh your local cache form here
This happens frequently if you have created the stored proc since you opened the SQL manager studio session. Refreshing the Object Explorer does not refresh this data for the syntax checker. Opening a new instance of studio will refresh the intellisense data.
I backed up my database table's and entire schema into .sql script using Visual Studio's Database Publishing Wizard.
I then tried to re-create those tables on another PC, not before re-creating the database itself, with the same exact name and everything (using a script that I created via SSMS's Script Database as).
I then open that tables .sql file using SSMS and execute it.
SSMS reports:
Command(s) completed successfully
But examining Object Explorer reveals that no tables were created.
Why is this happening?
What have I missed?
I've just been having the exact same problem symptoms also using Visual Studio's Database Publishing Wizard, - but with a slightly different cause / fix.
Even though SQL Server Management Studio says it is connected to the correct database (in the drop down in the ribbon, and in the status bar of the window), it wasn't actually connected to anything.
To identify and fix either:
SELECT DB_NAME() AS DataBaseName
If you get
master
(or any other unexpected database name) as the result, then you are connected to the wrong database and should select the correct DB from the dropdown. This was the cause of your problem.
If you get
Command(s) completed successfully
then somehow you aren't connected at all - this happened to me.
To fix, click the "change connection" button to disconnect and reconnect.
Check whether you have selected database. Most of the times we execute query in Master db by mistake.
-- Mark as answered if this answer really answered your question
Check if you are running "Execute" or jut Parsing the code. It was a late night, I was tired, and kept running a query to create a table, successfully, but no new table. The next day with a clear mind i noticed that i was not actually running the query, i was parsing it.