wadehuang36
12/3/2016 - 2:09 AM

Delete All Tables

Delete All Tables

declare @SQL varchar(max) = (
    select 
        'alter table ' + quotename(schema_name(schema_id)) + '.' +
        quotename(object_name(parent_object_id)) +
        ' drop constraint '+quotename(name) + ';'
    from sys.foreign_keys
    for xml path('')
);

EXECUTE(@SQL);




declare @SQL nvarchar(max)

SELECT @SQL = STUFF((SELECT ', ' + quotename(TABLE_SCHEMA) + '.' + quotename(TABLE_NAME) 

FROM INFORMATION_SCHEMA.TABLES
FOR XML PATH('')),1,2,'')

SET @SQL = 'DROP TABLE ' + @SQL

EXECUTE (@SQL)