Building a SQL Restore Script When Your Backup Runs

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 with that.  

Posted in SQL Server Tagged with: , , , , , , ,

Determining how much of your data file has been modified

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. What is really interesting about this is that with

Posted in SQL 2017, TSQL Tagged with: , , , , , , ,

My CheckDB Script

From time to time I get asked about checkDB, and there are many solutions out there, but I have one that I generally use that is very simple and does the job. The script below created a stored procedure in

Posted in Uncategorized Tagged with: , , , , , , ,

Temporary Stored Procedures #sproc

Yes, you can create temporary stored procedures by prefixing the name of the sproc with a #. The temporary stored procedure is sort of a “leave no trace” stored procedure that is only good for your session. If you use

Posted in TSQL Tagged with: , , , , , , ,

Drop a trigger after a specific date

  The question of how to delete a trigger after a specific date came up.  Here is what could be done. If you want to trigger to disappear after a specific date or time, you can just drop the trigger

Posted in TSQL Tagged with: , , ,

How Do You Check if a Database Exists…

How do you check if a database exists, drop it and recreate it for testing purposes? After running the Database Corruption Challenge for several weeks now, I have seen many scripts to drop and recreate a database. This makes it

Posted in Corruption Tagged with: , ,

Database Corruption Challenge Week 4 Results

It is my pleasure to announce the winners in the Week 4 Database Corruption Challenge. But first how about a rundown of challenge. In order to make up for the difficult time that Challenge #3 was issued, Challenge #4 was

Posted in Corruption Tagged with: , , , , ,

Week 4 – Building the Corrupt Database

The following are the steps that I went through to create a more difficult Database Corruption Challenge for Week 4. Here is how I built the database, nothing fancy, however I did add an extra FILEGROUP called [UserObjects]. Notice, that

Posted in Corruption Tagged with: , , , , , , ,

Using the TSQL IIF Function

Here is a quick video tutorial on how to use the IIF function on SQL Server 2012, SQL Server 2014 0r newer. This was originally part of my free SQL query training for the 70-461 certification exam. Here is the sample

Posted in 70-461 Training Tagged with: , , , , , , ,

Simple Cursor Example : FORWARD_ONLY vs FAST FORWARD

First lets take a look at two queries using CURSORS, the first one will use the FORWARD_ONLY type cursor, and the second will use the FAST_FORWARD type cursor. These two types sound very similar, but perform quite differently. Now for

Posted in 70-461 Training, TSQL Tagged with: , , , , , , ,