Hello I would like to know is is possible to drop all tables in database what was created under custom schema for example DBO1...with one sql query or special script.
T
Modification of acepted answer that works just copy pasted.
Change db
to your database and set @dbSchema
to your schema.
USE db -- CHANGE TO YOUR DB
GO
DECLARE @dbSchema NVARCHAR(200);
SET @dbSchema = 'dbo' -- CHANGE TO YOUR SCHEMA
DECLARE @SqlStatement NVARCHAR(MAX)
SELECT @SqlStatement =
COALESCE(@SqlStatement, N'') + N'DROP TABLE ' +'[' + @dbSchema +']' + '.' + QUOTENAME(TABLE_NAME) + N';' + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = @dbSchema and TABLE_TYPE = 'BASE TABLE'
EXEC sp_executesql @SqlStatement