Being a Database Developer or Administrator, often we work on Performance Optimization of the queries and procedures. It becomes very necessary that we focus on the right queries to get major benefits. Recently I was working on a Performance Tuning project. I started working based on query list provided by client. Client was referring the … Continue reading Tracking costliest queries
Category: Queries
T-SQL query to get the latest available backup chain
T-SQL query to return the latest available database backup chain (Full, Differential and Log) of individual databases along with their backup size and compressed size.
T-SQL script to purge all the tables including foreign key references
T-SQL script to purge all the tables including foreign key references. The script has been made smart enough to use TRUNCATE wherever there is no foreign key reference and to use DELETE wherever there is foreign key reference.
T-SQL query to copy data from one database to another database
T-SQL query to copy the rows of all the tables from one database to another database only if they have rows in Source DB and exact same Schema in both Source and Destination DB.
Pseudo Code for batch processing using WHILE LOOP
[code language="sql"] /* Note : Make sure your table/dataset which you wish to process in batches has the column with running number such as an identity column or if not then dump the data in some local scoped temporary/hash table with column as RowID which can be generated using the ROW_NUMBER() function if you are … Continue reading Pseudo Code for batch processing using WHILE LOOP