Search
 
SCRIPT & CODE EXAMPLE
 

SQL

how to drop all tables in sql

USE Databasename

SELECT  'DROP TABLE [' + name + '];'
FROM    sys.tables
Comment

drop all tables

DROP DATABASE db_name;
CREATE DATABASE db_name;
Comment

drop all data from tables

DELETE FROM my_table;			-- all rows, needs a COMMIT to validate
TUNCATE TABLE my_table;			-- all rows, quicker, no possible roolback
Comment

SQL Query to delete all the tables in a database

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
Comment

sql drop all tables

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
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle list dates without weekends 
Sql :: select last 30 days sql 
Sql :: sql server select first day of previous year 
Sql :: describe in sqlite3 
Sql :: mysql date range 
Sql :: zsh-syntax-highlighting zsh-autosuggestions 
Sql :: install mysql 5.7 
Sql :: sql concat 
Sql :: does insert into overwrite sql 
Sql :: mysql backup table 
Sql :: drop primary key oracle 
Sql :: connect mysql command line 
Sql :: mysql delete table with foreign key 
Sql :: myswql show full processlist 
Sql :: oracle apex view logs 
Sql :: sql query to select records entered in last 24 hours 
Sql :: postgres select duplicate columns 
Sql :: mysql select date range last 30 days 
Sql :: show column names in sql table 
Sql :: download sql server 2016 
Sql :: postgresql subtract date/hours 
Sql :: postgressql uuid 
Sql :: mysql delete entire row on condition 
Sql :: copy data from one table to another mysql 
Sql :: sql order by alphabetical 
Sql :: sql parent child tree query 
Sql :: oracle convert run duration to number 
Sql :: mysql change value 
Sql :: how to view created temporary tables in mysql 
Sql :: sql query to find percentage of null values in a table 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =