drop all tables in azure sql database

Solutions on MaxInterview for drop all tables in azure sql database by the best coders in the world

showing results for - "drop all tables in azure sql database"
Emelie
07 Jan 2021
1while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
2begin
3 declare @sql nvarchar(2000)
4 SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
5 + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
6 FROM information_schema.table_constraints
7 WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
8 exec (@sql)
9 PRINT @sql
10end
11
12
13while(exists(select 1 from INFORMATION_SCHEMA.TABLES 
14    where TABLE_NAME != 'database_firewall_rules' 
15    AND TABLE_TYPE = 'BASE TABLE'
16    AND TABLE_NAME NOT IN (select name from sys.external_tables)))
17begin
18 declare @sql1 nvarchar(2000)
19 SELECT TOP 1 @sql1=('DROP TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + ']')
20 FROM INFORMATION_SCHEMA.TABLES
21 WHERE TABLE_NAME != 'database_firewall_rules'
22    AND TABLE_TYPE = 'BASE TABLE'
23    AND TABLE_NAME NOT IN (select name from sys.external_tables)
24exec (@sql1)
25 PRINT @sql1
26end
27