@manhng

Welcome to my blog!

Sql Server Articles

November 22, 2017 02:00

SQL Server - Drop all tables in given schema using Powershell

https://gist.github.com/bhasto/4534514

https://stackoverflow.com/questions/27606518/how-to-drop-all-tables-from-a-database-with-one-sql-query

SQL Server 2008 delete all tables under special schema

This will generate all the DROP TABLE statements for you and PRINT the SQL statement out. You can then validate it's what you expect before copying and executing. Just make sure you are 100% sure...maybe take a backup first :)

DECLARE @SqlStatement NVARCHAR(MAX)
SELECT @SqlStatement =
COALESCE(@SqlStatement, N'') + N'DROP TABLE [SJR].' + QUOTENAME(TABLE_NAME) + N';' + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'SJR' and TABLE_TYPE = 'BASE TABLE'

PRINT @SqlStatement


https://www.red-gate.com/simple-talk/sql/database-administration/automating-sql-server-database-deployments-scripting-details/

https://www.red-gate.com/simple-talk/sql/database-administration/using-migration-scripts-in-database-deployments/

Script and create SQL Server objects quickly

https://github.com/sethreno/schemazen

https://blog.sqlauthority.com/2012/07/18/sql-server-generate-script-for-schema-and-data-sql-in-sixty-seconds-021-video/

https://blog.sqlauthority.com/2011/05/07/sql-server-2008-2008-r2-create-script-to-copy-database-schema-and-all-the-objects-data-schema-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/

Categories

Recent posts