I have hundreds of procedures auto generated by DataSync.
I don't have the time and sense to delete them manually.
They all start with DataSync.
Is there a way to delete all stored procedures where the name start with DataSync.
?
Use the DROP SCHEMA command to drop a schema. When you drop a schema, you drop all the objects defined within that schema. You cannot drop a schema if it is being accessed in other user sessions or if it is the default schema of the database.
Delete stored procedure SQL Server management studio Open the object explorer window and navigate to Programmability > Stored Procedures under your database. Here you can see the list of stored procedures that are created in the database.
DROP TABLE removes tables from the database. Only the table owner, the schema owner, and superuser can drop a table. To empty a table of rows without destroying the table, use DELETE or TRUNCATE . DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table.
Use the information_schema.routines (which is fairly standard across RDBMSs such as MSSQL,Mysql):
If your proc names start "DataSync." then they are probably in a schema, so you can find them with:
select
'DROP PROCEDURE [' + routine_schema + '].[' + routine_name + ']'
from
information_schema.routines where routine_schema = 'DataSync' and routine_type = 'PROCEDURE'
If your proc names start "DataSync" then you can find them with:
select
'DROP PROCEDURE [' + routine_schema + '].[' + routine_name + ']'
from
information_schema.routines where routine_name like 'DataSync%' and routine_type = 'PROCEDURE'
If you wanted to execute all these drop statements, you can build a single execute using FOR XML PATH as follows:
declare @sql varchar(max)
set @sql = (
select
'DROP PROCEDURE [' + routine_schema + '].[' + routine_name + '] '
from
information_schema.routines where routine_schema = 'DataSync' and routine_type = 'PROCEDURE'
FOR XML PATH ('')
)
exec (@sql)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With