Last active
February 6, 2019 14:24
-
-
Save csharpforevermore/e1fb7f1976fb1bded3b03063daee6af7 to your computer and use it in GitHub Desktop.
Search all stored procedures for text string 'szUserName'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://stackoverflow.com/questions/10637976/how-do-you-check-if-identity-insert-is-set-to-on-or-off-in-sql-server | |
SELECT OBJECTPROPERTY(OBJECT_ID('MyTable'), 'TableHasIdentity'); | |
-- when using an API wrapper, one can reduce the entire check to just checking for rows. For instance when using C#'s SqlDataReaders property HasRows and a query construct like: | |
SELECT CASE OBJECTPROPERTY(OBJECT_ID('MyTable'), 'TableHasIdentity') WHEN 1 THEN '1' ELSE NULL END | |
-- more flexibility but needs column name | |
SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('MyTable', 'U') AND name = 'MyTableIdentityColumnName'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ROUTINE_NAME, ROUTINE_DEFINITION | |
FROM INFORMATION_SCHEMA.ROUTINES | |
WHERE ROUTINE_DEFINITION LIKE '%szUserName%' | |
AND ROUTINE_TYPE='PROCEDURE' | |
SELECT OBJECT_NAME(id) | |
FROM SYSCOMMENTS | |
WHERE [text] LIKE '%szUserName%' | |
AND OBJECTPROPERTY(id, 'IsProcedure') = 1 | |
GROUP BY OBJECT_NAME(id) | |
SELECT OBJECT_NAME(object_id) | |
FROM sys.sql_modules | |
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1 | |
AND definition LIKE '%szUserName%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment