I have procedure that is hidden , I know it hard to unhide the procedure on sybase but is there a query that tells the procedure if its hidden or not ? I tried sysobjects but it I couldnt find any way
It is indicated by the syscomments.status columns.
See http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36274.1600/doc/html/san1393052468258.html
Related
I need to do a check to see which stored procedures have table updates in them that don't update certain columns. I found the code of the stored procedure in the sys.sql_modules, but I don't know how could I make this check. The stored procedures may contain more UPDATEs and INSERTs. I am using Microsoft SQL.
Assuming you are curious to find stored procedures that update TblA and do not update ColA, you could do something like:
SELECT * FROM sys.sql_modules
WHERE definition LIKE 'UPDATE TblA' AND
definition NOT LIKE 'SET ColA';
This can get ugly if people do not format their source well, but you can adapt this technique to handle that if you need to.
I have changed the name of a stored procedure in SQL Server using the GUI and it changed, but whenever I try to modify procedure code with sp_helptext, in the query editor, it was showing the old procedure name.
How to get rid of the problem?
It seems that this definition is being updated only when you run ALTER statement..
Do not use use sp_helptext for scripting!
If you want to modify the procedure code, use SSMS GUI: right click on procedure > alter to > new query.
Or use one the following to acquire the defition from T-SQL:
select object_definition(object_id('uspTestProc'))
select * from sys.sql_modules where object_id = object_id('uspTestProc')
Apart from the problem you're experiencing, in sp_help docs you can read about sp_help result: "Each row contains 255 characters of the Transact-SQL definition". This means that if you have lines longer than 255 character in procedure code, such line will be broken down into 255 char chunks. In best case scenario your code won't work, but if you're unlucky it will work and produce incorrect result, for example if some code that you had in a comment will be movde to new line and become uncommented.
Renaming Procedure names in SQL Server is not a good option as it does not update the procedure text.
Avoid renaming procedures and prefer DROP and CREATE.
I have observed the following feature when I rename a stored procedure.
sp_RENAME 'User_Validate', 'sp_UserValidate'
And when I do sp_helptext sp_UserValidate the procedure's name that i see is
CREATE PROCEDURE User_Validate
(#userEmail nvarchar(200),
#userPassword nvarchar(32))....
Why doesn't the name get updated in the stored procedure?
But when I check
select * from sys.procedures
I find the name field being updated? What's the reason behind it? The only logical conclusion I can draw is it's better to drop the procedure and recreate with a new name.
edit 1:
If I do sp_helptext User_Validate it returns "The object 'User_Validate' does not exist in database 'Process' or is invalid for this operation." But when I view the stored procedure the name User_Validate is still there.
Note: I know that renaming stored procedures is not a good practice, the question I asked is out of curiosity.
sp_helptext does not reverse engineer the procedure, it simply shows the original T-SQL batch that created the procedure, including comments and white spaces.
sp_rename is not recommended for renaming stored procedures, views, triggers, and user defined functions
Your conclusion is right, you should drop and re-create it with a new name. The same is stated in BOL - Rename a Stored Procedure
You should also check the dependencies of a stored procedure because renaming a stored procedure may cause dependent objects to fail if they are not updated to match the change
Hope this helps
I have a query in a stored procedure that needs to be executed on different servers and databases according to some parameters.
How can I do this without using neither exec, nor sp_executesql?
I'm using SQL Server 2008.
Thank you.
UPDATE
I've found some links
http://www.eggheadcafe.com/software/aspnet/29397800/dynamically-specify-serve.aspx
http://www.sommarskog.se/dynamic_sql.html
Is using SYNONYM possible solution? If yes, than how?
UPDATE 2
I forgot to mention that all this servers are linked to the server where stored procedure is stored.
UPDATE 3
OPENROWSET or OPENDATASOURCE are not accessible either. I need a solution without building query string concating server name, schema name, db name.
It surely can be done by using if or case in stored procedure, but if we have 37 variations, then it's not a good solution.
Any other suggestions?
Nobody wants to answer, so I'll do it myself, just to have accepted answer.
There's isn't any way to do this. You need to use one of specified suggestions, anyway the query must be generating by concatenating.
Does OPENROWSET or OPENDATASOURCE help?
EDIT: If it works, you can change the database at runtime & execute the query using the present connection. I cannot see any other way of executing query the way you want.
What is wrong with running query using string i.e dynamic query?
/* DO THIS FOR EACH TABLE IN THE PROCEDURE*/
--BEGIN TABLE_1
DECLARE #LINKEDSERVER AS VARCHAR(50)
SET #LINKEDSERVER = DBO.FN_RETURN_SERVER('SBROUBLES')
DROP SYNONYM MYLINKEDSERVER
EXEC (' CREATE SYNONYM MYLINKEDSERVER FOR ' + #LINKEDSERVER + 'ANYDB.DBO.ANYTABLE')
--- END TABLE_1
-- UTILIZATION
SELECT COUNT(*) FROM MYLINKEDSERVER
--AND FN_RETURN_SERVER COULD BE ANY SELECT CASE ON SQL AS WELL
So, not sure what is happening. But I have stored procedure and it keeps disappearing out of my DB in SQL 2k.
I can add it again and then try to execute it from my web app and i get an exception saying the stored procedure cant be found. So then ill go back to management and refresh and its gone again !?!
here is the config for the stored proc:
set ANSI_NULLS OFF
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[USP_Equipment_Delete]
#EquipmentID int
AS
DELETE FROM [dbo].[Equipment]
WHERE
[EquipmentID] = #EquipmentID
None of my other stored procedure disappear. This is the only one. I have easily 100 in there. They all use the same SQLHelper class. This one just keeps disappearing!!!??!!
Any help or suggestions are appreciated!
Thanks so much!
You were creating this or another stored proc and at the end of your code, maybe after a comment, where you did not see it you have a drop of this proc.
Take a look at your db using:
select syo.name
from syscomments syc
join sysobjects syo on
syo.id = syc.id
where syc.[text] like '%DROP PROC%'
I had the same problem and I just fixed it:
In the script file it was missing the "GO" statement between the end of the stored procedure and the beginning of the next "IF EXIST THEN DROP" statement.
So what happened was that the drop statement was getting appended to the end of whatever stored procedure was above it in the script. So when the software ran the stored procedure it would drop whatever stored procedure was below it in the script.
It seems so obvious to us now but didn't make any sense at the time. We found it running the SQL profiler against a customer's database that was having the problem in the field.
Are you using the correct database?
Try
using [database name]
prior to executing your stored procedure, just to make sure.
Do you have a CREATE PROCEDURE anywhere? You can't ALTER a procedure if it doesn't exist.
Perhaps the code to access the stored procedure is using a different context other than dbo. Make sure to add dbo.USP_Equipment_Delete to the code using it.
I was facing the problem that all Stored Procedures with a create statement disappeared from the database after execution.
The Solution was: The database user should have the rights to drop,create and alter on the database in which the "Stored Procedures" are going to be created.
Perhaps there's a job thats restoring an old backup periodically?
Check if the "Initial Catalog" in your connection string is set to the correct database.
Put the database in single user mode (and make sure you're the single user) and check if the procedure still disappears every hour?
If it's there, then this query must return a record:
SELECT * FROM sysobjects
WHERE id = OBJECT_ID('USP_Equipment_Delete')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1