Tag Archives: truncate

SQL How to empty all tables in a database

You might need to purge all the data in all the tables in a particular database. For this we can use the following script.

USE <database name>
DECLARE @TableName AS VARCHAR(MAX)
DECLARE table_cursor CURSOR
FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_NAME LIKE '%_Partition%'
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @SQLText AS NVARCHAR(4000)
SET @SQLText = 'TRUNCATE TABLE ' + @TableName
EXEC sp_executeSQL @SQLText
FETCH NEXT FROM table_cursor INTO @TableName
END
CLOSE table_cursor
DEALLOCATE table_cursor

(41)

How to: Manually purge Exchange server logs safely

Many had this problem when in crisis, one would need to purge the Exchange logs but ended up not doing it for the fact that it would be risky and not safe. One can manually and safely purge the Exchange logs with the below script. Open a command prompt and type the following.

Note: the m: would be your drive where the Exchange Mailbox databases are.

diskshadow
add volume m:
begin backup
create

At this moment, nothing will happen and after some time the screen will be populated. As soon as you see the prompt, enter the below.

end backup

After some time, you will see the space decreasing and the logs being purged. Although this works on Exchange 2010, it would be the same for Exchange 2007.

(3314)