Keeping it Simple: Blog Introduction Post
Hopefully people will find this blog to be both helpful and offer up some decent advice with relevant content. It will also serve as a placeholder for experiences, lessons learned, and some of the scripts I have used both currently and over the past 10 years.
My goal will be to update content at least weekly but we will see how that shapes out as I really enjoy all things SQL Server while juggle being a husband and crisis negotiator of 5 wonderful kids. I have decided to follow what many others have done and start putting my SQL Server journey and thoughts out there for people to learn.
We will kick things off super simple with the following script that I use after restoring anything from production to a dev/test environment where I do not care about a database being in FULL Recovery so we flip it to simple and shrink the log file:
My goal will be to update content at least weekly but we will see how that shapes out as I really enjoy all things SQL Server while juggle being a husband and crisis negotiator of 5 wonderful kids. I have decided to follow what many others have done and start putting my SQL Server journey and thoughts out there for people to learn.
We will kick things off super simple with the following script that I use after restoring anything from production to a dev/test environment where I do not care about a database being in FULL Recovery so we flip it to simple and shrink the log file:
--xSimple
--Sets the DB to simple recovery and truncates the log file.
DECLARE @CURRENTDB VARCHAR(128);
DECLARE @LOG VARCHAR(128);
DECLARE @QUERY VARCHAR(512);
SET @CURRENTDB = DB_NAME();
-- NOTE: Fails if the DB has more than one log file.
SET @LOG = (SELECT Name FROM sys.database_files WHERE type_desc = 'LOG');
SET @QUERY = 'ALTER DATABASE [' + @CURRENTDB + '] SET RECOVERY SIMPLE;';
SET @QUERY = @QUERY + 'DBCC SHRINKFILE ([' + @LOG + '], 1);';
EXEC (@QUERY);
--End xSimple
--Done
--Sets the DB to simple recovery and truncates the log file.
DECLARE @CURRENTDB VARCHAR(128);
DECLARE @LOG VARCHAR(128);
DECLARE @QUERY VARCHAR(512);
SET @CURRENTDB = DB_NAME();
-- NOTE: Fails if the DB has more than one log file.
SET @LOG = (SELECT Name FROM sys.database_files WHERE type_desc = 'LOG');
SET @QUERY = 'ALTER DATABASE [' + @CURRENTDB + '] SET RECOVERY SIMPLE;';
SET @QUERY = @QUERY + 'DBCC SHRINKFILE ([' + @LOG + '], 1);';
EXEC (@QUERY);
--End xSimple
--Done
Comments
Post a Comment