Search
 
SCRIPT & CODE EXAMPLE
 

SQL

drop all tables in azure sql database

while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
begin
 declare @sql nvarchar(2000)
 SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
 + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
 FROM information_schema.table_constraints
 WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
 exec (@sql)
 PRINT @sql
end


while(exists(select 1 from INFORMATION_SCHEMA.TABLES 
    where TABLE_NAME != 'database_firewall_rules' 
    AND TABLE_TYPE = 'BASE TABLE'
    AND TABLE_NAME NOT IN (select name from sys.external_tables)))
begin
 declare @sql1 nvarchar(2000)
 SELECT TOP 1 @sql1=('DROP TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + ']')
 FROM INFORMATION_SCHEMA.TABLES
 WHERE TABLE_NAME != 'database_firewall_rules'
    AND TABLE_TYPE = 'BASE TABLE'
    AND TABLE_NAME NOT IN (select name from sys.external_tables)
exec (@sql1)
 PRINT @sql1
end
Comment

PREVIOUS NEXT
Code Example
Sql :: how to create a table in sql 
Sql :: date format mysql 
Sql :: multiple like in sql 
Sql :: docker create postgresql database 
Sql :: mysql if null 
Sql :: mysql trim spaces 
Sql :: android sqlite add column if not exists 
Sql :: mariadb json_extract 
Sql :: return result of function in postgresql 
Sql :: mysql get all tables from a specific database 
Sql :: sql if clause within where clause 
Sql :: mysql grant select update insert delete 
Sql :: postgresql get connection string 
Sql :: mysql age by birthdate 
Sql :: mysql declare variable 
Sql :: enable foreign key checks postgres 
Sql :: database timezone 
Sql :: division by zero postgres 
Sql :: get clob size oracle 
Sql :: bigquery add days to date 
Sql :: mysql select row with min date 
Sql :: how to find average in sql 
Sql :: rename column name sql server 
Sql :: how to select random rows from table 
Sql :: mysql import database 
Sql :: expo sqlite 
Sql :: ON DUPLICATE KEY UPDATE for postgres 
Sql :: sql oracle update multiple rows 
Sql :: sql find all different values in column 
Sql :: sqlite3 pragma foreign keys 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =