DROP Tables and Procedures Using MS SQL Server

DROP Tables and Procedures Using MS SQL Server


-- query to get all Tables

DECLARE @sql NVARCHAR(max)=''
SELECT @sql += ' DROP PROCEDURE  ' + QUOTENAME(TABLE_SCHEMA) + '.'+ QUOTENAME(TABLE_NAME) + '; '
FROM   INFORMATION_SCHEMA.PROCEDURES
WHERE  TABLE_TYPE = 'BASE TABLE'

SELECT @SQL 

-- after executing the below query, All tables will dropped.
EXEC Sp_executesql @sql

-- query to get all procedures

SELECT 'DROP PROCEDURE [' + SCHEMA_NAME(p.schema_id) + '].[' + p.NAME + '];'
FROM sys.procedures p 

Comments

Popular posts from this blog

Tree view in winforms using c#

how to Replace null value with 0 Using C#

how to fetch all HTML Table Records and modify all records accordingly using jquery and Javascript