Search code examples
azure-synapse

How to Remove All Views from Azure Synapse SQL Serverless Inbuilt


Can let me know how to remove views/tables from Azure Synapse Inbuilt SQL Serverless Pool.

Its easy enough to remove individual tables/views using following:

use [DatabaseName] 
GO 
drop EXTERNAL table schemaname.tablename

But I would to remove all the views/tables shown here:

enter image description here


Solution

  • Run the following T-SQL query which builds a dynamic SQL statement to drop all views:

    declare @sql nvarchar(max) = (
    select STRING_AGG('drop view ['+s.name+'].['+v.name+']; ','
    ')
    from sys.views v
    join sys.schemas s on s.schema_id = v.schema_id
    where v.is_ms_shipped = 0
    )
    
    exec(@sql)