Delete Duplicate Records from the ResultSet
WITH CTE AS(SELECT ResultTypeID, Info1, Info2, Info3, Info4,RN = ROW_NUMBER() OVER(PARTITION BY ResultTypeID, Info1, Info2, Info3, Info4 ORDER BY MatchPercentage DESC)FROM #tmpSearchResults)DELETE FROM CTE WHERE RN > 1 Note: In the Partition By section write the name of the Column or Columns you want to have unique.
Create Temporary Table
IF OBJECT_ID(‘tempdb..#tmpSearchResults’) IS NOT NULLDROP TABLE #tmpSearchResults
Reseed Table Primary Column
DBCC CHECKIDENT (‘TableName’, RESEED, 0);GO Note: 0 is the number to which you want to reset. It could be any number. For example if you have 200 records but you want to keep only 10 records and delete the rest, then you may reset the seed to 10 so that the next insert will be for record id 11.
Get the List of all the queries executed on a Particular SQL Database
Use [DB NAME] SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql ORDER BY execquery.last_execution_time DESC
Get the count of records in all tables of a database
CREATE TABLE #counts ( table_name varchar(255), row_count int ) EXEC sp_MSForEachTable @command1=’INSERT #counts (table_name, row_count) SELECT ”?”, COUNT(*) FROM ?’ SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC DROP TABLE #counts