Tuesday, April 29, 2014

Drop all SqlQueryNotificationStoredProcedure from Database

below query will drop all SqlQueryNotificationStoredProcedure available in specific database.

ALTER AUTHORIZATION ON DATABASE :: <Your Database Name> TO <[login user]>

for example your DB name : TestDB and sql server login user: sa, then you can write
ALTER AUTHORIZATION ON DATABASE :: TestDB TO [sa]

Example :


ALTER AUTHORIZATION ON DATABASE :: TestDB  TO [sa]
DECLARE @PROCNAME VARCHAR(500)
DECLARE CUR CURSOR 
FOR SELECT [NAME] FROM SYS.OBJECTS WHERE TYPE IN (N'P', N'PC') AND NAME LIKE 'SQLQUERYNOTIFICATIONSTOREDPROCEDURE%'

OPEN CUR
FETCH NEXT FROM CUR INTO @PROCNAME

WHILE @@FETCH_STATUS = 0
BEGIN

  EXEC ('DROP PROCEDURE [' + @PROCNAME+']')
  FETCH NEXT FROM CUR INTO @PROCNAME

END
CLOSE CUR
DEALLOCATE CUR



No comments:

Post a Comment