Archive

Posts Tagged ‘PASS’

Presenting – The Odyssey Continues

GIVE ALL THE PRESENTATIONS
As I’ve mentioned before, I set a goal at the beginning of the year to average a presentation a month in 2014. My presentation, Designing a Recovery Strategy, at the Wisconsin SQL Server User Group this month put me halfway there.

In June, I am presenting Designing a Recovery Strategy again at SQL Saturday #307 in Iowa City on the 7th. And then, for the first time ever, I will be presenting twice on the same day at SQL Saturday #286 in Louisville on the 21st. I’ll be doing Designing a Recovery Strategy and Interrogating the Transaction Log (now with 2014!) If you are close to either event, I highly recommend attending. It is a great opportunity to get a free day of training and meet other members of the SQL community.

I close out the month by presenting Interrogating the Transaction Log at MADPASS June 25th. It has been a wild ride, but I’ve enjoyed every minute of it. Presenting is a great way to give back to the SQL community and I learn more than I thought possible every time I put a presentation together.

sp_AutomateDBRestore – Now With Table-Valued Parameters!

After several weeks of procrastination, I have finished the latest version of sp_AutomateDBRestore. The previous versions of the procedure built the restore statements using sys.database_files for the restored database, msdb.dbp.backupset, and msdb.dbo.backupmediafamily. This process works great if the instance is up and running, but if the instance is unavailable it won’t work.

To handle this circumstance, I have added a table-valued parameter to the procedure allowing a list of backup files and backup file types to be passed in. This way, you can generate a restore statement as long as you have the backup files available. The proc uses RESTORE FILELISTONLY and RESTORE HEADERONLY statements to retrieve the physical and logical file names. Additionally, I’ve added parameters @backupfilepath and @logfilepath to allow a restore of the database to a different physical file than the source database. Here is the code to create a user-defined table type, followed by a call using the new parameters:

USE [master]
GO

CREATE TYPE [dbo].[backupfiletype] AS TABLE(
	[backupfilename] [varchar](255) NULL,
	[backupfiletype] [varchar](30) NULL
)
GO
DECLARE @backuptvp AS backupfiletype

INSERT INTO @backuptvp
VALUES
('C:\Backup\WIN-MK86UPCRGFF\multifile\FULL\WIN-MK86UPCRGFF_multifile_FULL_20140513_091120.bak','FULL'),
('C:\Backup\WIN-MK86UPCRGFF\multifile\LOG\WIN-MK86UPCRGFF_multifile_LOG_20140513_091135.trn','LOG'),
('C:\Backup\WIN-MK86UPCRGFF\multifile\LOG\WIN-MK86UPCRGFF_multifile_LOG_20140513_091203.trn','LOG'),
('C:\Backup\WIN-MK86UPCRGFF\multifile\LOG\WIN-MK86UPCRGFF_multifile_LOG_20140513_091354.trn','LOG')


DECLARE	@return_value int

EXEC	@return_value = [dbo].[sp_automateDBRestores]
		@sourcedbname = multifile,
		@restoredbname = multifile,
		@droprestoredb = 0,
		@noexec = 1,
		@datafilepath = 'C:\testrestore\',
		@logfilepath = 'C:\testrestore\',
		@TVP = @backuptvp

SELECT	'Return Value' = @return_value

GO

You can find the code for the updated procedure at my Presentation Slides and Scripts page under Wisconsin SQL Server User Group. As usual, feel free to leave any questions or comments in the comments section for the post.

Categories: PASS, SQL Server, T-SQL Tags: , ,

SQL Saturday #291

Speaker dinner at the Schnitzel Platz (MarkV is an instigator) -Thanks to Dave Mattingly for the photo

Speaker dinner at the Schnitzel Platz (MarkV is an instigator) -Thanks to Dave Mattingly for the photo


SQL Saturday #291 took place this past Saturday at DeVry University in Addison, Illinois. It was my eighth SQL Saturday, and it was the first one I helped run. I want to thank Bill Lescher (t), Wendy Pastrick (b|t), Bob Pusateri (b|t), Jamie Samsel, and Andy Yun (b|t) for all of their hard work. I had a great time and have heard positive feedback from all of the attendees I’ve spoken with.

The hard work these folks put in wouldn’t mean anything without the speakers who volunteer their time and pay their own way to attend these events. I especially want to thank Jim Dorame (b|t), Merrill Aldrich (b|t), Eric Boyd (b|t), and Grant Fritchey (b|t). With only 15 minutes’ notice, Jim stepped in to replace a speaker who did not arrive, moving from his scheduled noon slot to 9:15. Then Jim, Merrill, Eric, and Grant held a PowerShell panel in Jim’s original slot. Their willingness to take on extra responsibility epitomizes the SQL community for me, and went a long way to making the event such a success.

Finally, I want to thank everyone who attended SQL Saturday #291. Without you, the SQL community would not exist. I spoke to a number of first-time attendees, and I hope they all come back again. The SQL community has given me more than I could ever give back. I’ve made great friends, learned from world-renowned experts, and grown personally and professionally. I met a current co-worker at SQL Saturday Chicago last year and my work in the community had a lot to do with my getting that job.

If you attended SQL Saturday and got something out of it, consider giving back. Presenting, blogging, volunteering, and answering questions on forums are all great ways to give back. If you haven’t already, register for your local PASS user group. If you don’t have a local user group, consider starting one. I’ve run the Chicago SQL Server User Group since July of 2012 and have had a blast. Feel free to contact me if you have any questions.

SQL Milestones

April 13, 2014 Leave a comment

The past few months have been full of firsts for me.

  • I started working at Apparatus February 17th. I wanted opportunities to learn new things, and I have not been disappointed.
  • Last night, I gave my fourth presentation of the year. With user groups lined up from now through August, I am on pace to meet my goal of averaging one presentation per month this year.
  • March marked the second anniversary of this blog. In that time, I’ve written 61 posts. While this is well short of my initial goal of a post a week, I’m hoping the constant learning opportunities at Apparatus will help me pick up the pace.
  • I hit 1,000 views on this blog for the first time in a month. I am really excited about this, but at the same time, it shows me how much room I have to grow.

It is just about four years since I attended my first SQL Saturday. Thanks to Jes Borland (b|t) for inspiring me to make my voice heard. And it’s just about three years since I attended SQL Skills’ Interals Immersion Event. Thanks to Paul Randal (b|t) and Kimberly Tripp (b|t) for giving me my first opportunity to present on SQL Server outside of work. Finally, I want to thank the members of the SQL community who have taught, helped, and inspired me. There are too many of you to mention, but you’ve made the past four years the most enjoyable and fulfilling of my life.

thankyouhc

Categories: Career, Presenting Tags: , ,

Update to Downgrading SQL Server Enterprise to Standard Scripts

October 24, 2013 Leave a comment

It’s hard to believe that I wrote this post almost a year ago. It’s been my most popular post, so I wanted to let people know about a change to one of the scripts. Many thanks to reader Francesco for pointing out an error. The Attach Script uses sp_msforeachdb and in the original script, I failed to wrap the ? wildcard in square brackets. As a result, database names containing dashes (I’m looking at you SharePoint), would not resolve properly. The script has been updated.

Having seen Kevin Kline (b|t) and Aaron Bertrand (b|t) present 10 Query Tuning Techniques Every SQL Programmer Should Know at this year’s PASS Summit, I know I should update the code to use Aaron’s sp_foreachdb. I will put that on the list of things to learn. That is why I love this job, because there is always something new to learn.

Strange Results from sys.fn_physlocformatter

October 17, 2013 2 comments

I’m writing from Charlotte, North Carolina where I’m attending my fifth PASS Summit. I hope to write a series of posts recapping my experiences, but I wanted to write about something I learned in Paul White’s (b|t) pre-conference session, Understanding the Optimizer and Interpreting Execution Plans. The session was amazing and I think I’ll spend the next year going through his scripts.

If you’ve read my blog you know I love internals. Paul introduced me to a function called sys.fn_physlocformatter. In SQL Server 2008 and beyond, %%physloc%% is a virtual column that returns the file, page and slot of each row of a result set in byte-reversed, hex format. That means it is hard to read. If you don’t believe me, here is an example of the query and its result:

USE MYTEST
GO

SELECT %%physloc%% AS [physloc],*
FROM MYTestTable

 

physloc results

 

fn_physlocformatter takes that hex value and formats it into a colon-delimited value that is much more readable. Here’s the query above, replacing %%physloc%% with fn_physlocformatter:

SELECT sys.fn_PhysLocFormatter(%%physloc%%),*
FROM MYTestTable

 

fn_physlocformatter results

 

After Paul showed us the function, I did a search to get more information and came across this post. Using the example provided, I wrote the following query to return a count of the number of rows written to each page:

SELECT SUBSTRING(sys.fn_PhysLocFormatter(%%physloc%%),4,(CHARINDEX(':',sys.fn_PhysLocFormatter(%%physloc%%),4) - 4)) [Page ID], COUNT(*) AS [Row Count]
FROM MYTestTable
GROUP BY SUBSTRING(sys.fn_PhysLocFormatter(%%physloc%%),4,(CHARINDEX(':',sys.fn_PhysLocFormatter(%%physloc%%),4) - 4))
ORDER BY [Row Count]

The sample code from the link above contains code to insert nine rows to MYTestTable2 at a time. I’ve listed the table definition and insert code below.

USE MYTEST
GO

CREATE TABLE MYTestTable2
(MYID INT IDENTITY, 
NAME CHAR(500), 
LNAME CHAR(500))
GO

INSERT INTO MYTestTable2 VALUES ('NAME-1','LNAME-1');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-2','LNAME-2');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-3','LNAME-3');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-4','LNAME-4');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-5','LNAME-5');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-6','LNAME-6');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-7','LNAME-7');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-8','LNAME-8');
GO
INSERT INTO MYTestTable2 VALUES ('NAME-9','LNAME-9');
GO

Because the rows are 1008 bytes long, seven rows will fit on one 8kb data page. After the initial insert of nine rows, I expected to see a page containing seven rows followed by a page with two rows. Here are the results after the initial insert:

 

Initial Insert Results

 

I continued running the nine inserts, to confirm that my code was working as expected. And for the next five runs, it did. The strange results didn’t show up until the seventh run, where I saw this:

 

strange results

 

After the seventh insert, something was causing seven pages to be allocated each with a single row inserted. This didn’t make any sense to me, so I continued investigating. I’ll show you the results of those investigations in my next post, sys.fn_physlocformatter – The Mystery Deepens!

SQL Saturday #239 – Another Presentation Under My Belt

July 28, 2013 1 comment

I just got home after a great weekend in Iowa City at SQL Saturday #239. I presented Interrogating the Transaction Log for the fifth time, this time with an extended section on virtual log files. Each time I’ve done the presentation, people have asked questions about VLFs and I always try to give the people what they want. Thanks to Ed Leighton-Dick (t), Sheila Acker (t) and everyone else who put on a great event. And a big thank you to everyone who attended my presentation. You can find the slides and demos here.

P.S. – You can also find the scripts and slides at the SQL Saturday #239 site as well.