Recursive CTE to Calculate Dates for the Last 30 Days
Have you ever needed to generate a list of dates for the last 30 days. There are lots of different ways to do this with… Read More »Recursive CTE to Calculate Dates for the Last 30 Days
Have you ever needed to generate a list of dates for the last 30 days. There are lots of different ways to do this with… Read More »Recursive CTE to Calculate Dates for the Last 30 Days
I came across this example when preparing my CTE presentation a while back. Which produces the following output. Download my book for FREE when you… Read More »Using a CTE in a Function to Split Up a Database Connect String
The question came up as to how do I parse a query string using TSQL. So here you go, using a common table expression, and… Read More »Using a CTE in a Function to Split Up a Query String
Part of SQL Server running queries is that once a query is analyzed, parsed and compiled, that compiled plan is kept in memory so that… Read More »How big is your procedure cache?
One of the common task that I have come across is the need to convert a list of results into a comma separated list. There… Read More »Converting part of a result set to a comma separated list
Running DBCC CHECKDB DBCC CHECKDB is one of the most essential tools in the SQL Server arsenal, providing a detailed examination of your database’s structural… Read More »Running DBCC CheckDB for all of your databases – quick script
You have a DBCC CHECKDB script running, something like the following, and it may take several hours to run to confirm if there is any… Read More »DBCC CheckDB or CheckTable – Find percent complete
It is handy to have a SQL Restore script ready to go for every backup that you run. Here is a script that will help… Read More »Building a SQL Restore Script When Your Backup Runs
SQL Server 2017 introduces a new column in the sys.dm_db_file_space_usage system table. The column is modified_extent_page_count, which tells how many pages have been modified in your data file since the last full backup.
SELECT * FROM sys.dm_db_file_space_usage;
What is really interesting about this is that with a little math you can calculate the percentage of your data file that has been modified. This would be useful when running differential backups to be able to determine if it would make more sense to run a full backup or a differential backup. Basically when your differential backup gets large enough, based on the number of modified_extent_page_count pages, then it may make sense to do a full backup and reset this counter, and get back to smaller differential backups.
Here is an example
SELECT df.name, df.physical_name, total_page_count, allocated_extent_page_count, modified_extent_page_count, 100.0 * modified_extent_page_count / allocated_extent_page_count as PercentChanged FROM sys.dm_db_file_space_usage fsu INNER JOIN sys.database_files df on df.file_id = fsu.file_id;
Now based on the Percent Changed column we can make some assumptions on the size of the differential backup, and decide if we want to do a differential backup or a full backup.
Read More »Determining how much of your data file has been modified
One of the common problems with when diagnosing what appears to be a slow scenario where there may be blocking involved is determining what is… Read More »Finding Blocking Queries