In this blog you will find various tools and articles that are useful to any DBAs. I will try to put more practical articles while at the same time post any database software bugs and some important tips on internals of sql server and optimization. Address cons and pros of different relational database management in use and new developments. This blog will also cover the market perception of different database system including some hard facts, reviews and benchmarks. Teshome Asfaw
Tuesday, April 24, 2012
Latest version of SQL server
To get an idea of what the latest version of SQL server will be, you can ask a SQL guru @Ask SQL Guru
Cannot shrink tempdb
How to shrink tempDB
SELECT * FROM sys.dm_exec_requests WHERE database_id = 2
select * from sys.dm_tran_locks
where resource_database_id= 2
select * from sys.dm_db_session_space_usage
where user_objects_alloc_page_count<> 0
SELECT * FROM sys.all_objects
where is_ms_shipped = 0
DBCC FREEPROCCACHE
BCC SHRINKFILE ('tempdev', 1024)
Purge all data in database
Recently I have been tasked to purge all data in the database. When trying to delete data from tables which have foreign key relationship the standard purge routine will fail or you have to spend time to get which table to purge first. Also there is an issue of identity as when you delete data from the table the identity will not go back to starting point. After few research, I have got the best method which is shown below.
1. Disable all constraints in the database using the following command
exec sp_msforeachtable "ALTER TABLE ? nocheck contraint all"
2. Delete all data in the database
exec sp_MSForEachTable "DELETE FROM ?"
3. Enable all constraints
exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
4. Reset tables with identity. Note when you run the following it will give you error if the table doesn't have identity column. Ignore the errors.
exec sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)"
Subscribe to:
Posts (Atom)