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;
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
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
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.