1.Right click the database
2.Go to "Tasks"
3.Click "Generate Scripts"
4.In the "Choose Objects" section, select "Script entire database and all database objects"
5.In the "Set Scripting Options" section, click the "Advanced" button
6.On "Script DROP and CREATE" switch "Script CREATE" to "Script DROP" and press OK
7.Then, either save to file, clipboard, or new query window.
8.Run script.
xxxxxxxxxx
-- To drop all tables in a database, do this:
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
-- If all of your tables are in a single schema, this approach could work
-- (assumes that the name of your schema is public)
xxxxxxxxxx
USE Databasename
SELECT 'DROP TABLE [' + name + '];'
FROM sys.tables
xxxxxxxxxx
-- Drop all tables from a database
USE your_database_name; -- Replace "your_database_name" with the actual name of the database you want to delete tables from
DECLARE @sql NVARCHAR(MAX) = N'';
SELECT @sql += N'DROP TABLE ' + QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) + ';
'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';
EXEC(@sql);
xxxxxxxxxx
-- Generate drop table commands for each table in the database
SELECT 'DROP TABLE ' || table_name || ';' AS drop_table_command
FROM information_schema.tables
WHERE table_schema = 'public' -- Specify the schema name if needed
AND table_type = 'BASE TABLE';
-- Execute the generated drop table commands to drop all tables
DO $$ DECLARE
drop_table_command text;
BEGIN
FOR drop_table_command IN (
SELECT 'DROP TABLE ' || table_name || ';' AS drop_table_command
FROM information_schema.tables
WHERE table_schema = 'public' -- Specify the schema name if needed
AND table_type = 'BASE TABLE'
)
LOOP
EXECUTE drop_table_command;
END LOOP;
END $$;
xxxxxxxxxx
DECLARE @sql NVARCHAR(max)=''
SELECT @sql += ' Drop table ' + QUOTENAME(TABLE_SCHEMA) + '.'+ QUOTENAME(TABLE_NAME) + '; '
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
Exec Sp_executesql @sql
xxxxxxxxxx
DO $$
DECLARE
v_table_name text;
BEGIN
FOR v_table_name IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE')
LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || v_table_name || ' CASCADE';
END LOOP;
END $$;
xxxxxxxxxx
BY LOVE
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
DECLARE @sql NVARCHAR(max)=''
SELECT @sql += ' Drop table ' + QUOTENAME(TABLE_SCHEMA) + '.'+ QUOTENAME(TABLE_NAME) + '; '
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
Exec Sp_executesql @sql
xxxxxxxxxx
-- Assuming the user wants to delete all tables in a MySQL database
-- Connect to your database first
-- Get a list of all tables in the database
SELECT GROUP_CONCAT(table_name) INTO @tablesToDelete
FROM information_schema.tables
WHERE table_schema = 'your_database_name';
-- Construct the SQL query to delete all tables
SET @query = CONCAT('DROP TABLE IF EXISTS ', @tablesToDelete);
-- Execute the SQL query to delete all tables
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;