You should be able to Delete data from all tables in a SQL server database by running the following TSQL command.
EXEC sp_MSforeachtable @command1 = ‘DELETE FROM ?’
Note: You might see some errors if there are foreign key constraints in your database. Just keep executing the above command until you see no errors and you should [...]
14May
Posted by admin as Asp.Net, SQL, Technology
You can delete all views from a database in SQL server by executing below TSQL statements.
DECLARE @viewName varchar(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = ‘v’
OPEN cur
FETCH NEXT FROM cur INTO @viewName
[...]
To delete all tables from a sql server database you can use the following TSQL command.
EXEC sp_MSforeachtable @command1 = ‘DROP TABLE ?’
Note: Running above command might throw errors if you have foreign constraints defined on some tables. Just click ok on the error dialog box and rerun the command. Keep executing this command until there [...]
Here is a way to delete all stored procedures from an SQL Server database
DECLARE @procedureName varchar(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = ‘p’
OPEN cur
FETCH NEXT FROM cur INTO @procedureName
[...]