By using this statement in SQL Server:
EXEC sp_msforeachtable 'DROP TABLE ?'
I know it's possible to delete all tables at once.
Is there a similar statement for views? I tried this hoping to be lucky: EXEC sp_msforeachview 'DROP VIEW ?' but it doesn't work!
By using this statement in SQL Server: EXEC sp_msforeachtable 'DROP TABLE ? ' I know it's possible to delete all tables at once.
Using SQL Server Management Studio In Object Explorer, expand the database that contains the view you want to delete, and then expand the Views folder. Right-click the view you want to delete and click Delete. In the Delete Object dialog box, click OK.
Here is the syntax to delete multiple views in SQL Server. In the above statement, you need to specify all views that you want to delete, in a comma-separated list. If you don't specify schema name, SQL Server will try to delete view from active schema. drop view products.
View is like a virtual table which enable us to get information of multiple tables. yes we can insert,update and delete view in sql server.
Here you have, no cursor needed:
DECLARE @sql VARCHAR(MAX) = '' , @crlf VARCHAR(2) = CHAR(13) + CHAR(10) ; SELECT @sql = @sql + 'DROP VIEW ' + QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(v.name) +';' + @crlf FROM sys.views v PRINT @sql; EXEC(@sql);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With