• Skip to main content
  • Skip to primary sidebar

DallasDBAs.com

SQL Server Database Consulting

  • Services
  • Pocket DBA®
  • Blog
  • Testimonials
  • Contact
  • About

Beginner

SQL101: Import/Export wizard

September 13, 2018 by Kevin3NF Leave a Comment

Do you need to quickly Import or Export data to/from SQL Server?  Do you want to avoid the hassle of creating and deploying an SSIS pacakge?

The SQL Server Import/Export wizard might be perfect for you!

The wizard steps you through the necessary pieces and is surprisingly flexible.  I cover the basics in this video (recorded in one shot, please excuse throat clears and “Ums”)

If you have comments, please leave them on the YouTube page (ideally) or down below.

Its very likely this is part 1 of at least two…trying to keep my videos to shorter lengths.

Thanks for reading!

Kevin3NF

Follow @Dallas_DBAs

Filed Under: Accidental DBA, Beginner, SSMS

Getting Started with Index and Execution Plan Basics

August 24, 2018 by Kevin3NF Leave a Comment

If you are a developer or new SQL Server DBA and have never really worked with query tuning, this post is for you.  If you are an experienced DBA/Tuner and want to nit-pick me saying field vs. column, feel free to leave a comment that I will delete or never publish, lol.  This is basics, yo…

I concentrate on how to measure the performance of a query, as well as the basics of “seeing” how SQL Server is executing the query to return the results.

I could type all of this up, but watching the video is going to be a WHOLE lot better teacher, so here you go:

As always, feel free to reach out via the comments here or on the video.  Or, follow me on Twitter and ask away!

Thanks for reading!

Kevin3NF

Follow @Dallas_DBAs

Filed Under: Accidental DBA, Beginner, Indexing Strategies, Performance Tuning

SQL 101: Extended Events – set up a basic session

August 6, 2018 by Kevin3NF Leave a Comment

Setting up your first Extended Event session is much simpler than I thought it would be!

Extended Events (XE) in SQL Server showed up first in SQL 2008, but they got a GUI in SQL 2012, making them much easier to work with on the fly.  I’m one of those old DBAs that was reluctant to move away from SQL Trace via Profiler for simple needs.  Of course for more complex issues and long-term tracking I used server-side tracing for many years.

With the advent of XE, Microsoft stopped enhancing SQL Trace.  Many of the new features of SQL are not in SQL Trace at all (180 in Trace compared to 1000+ in XE now).  In addition to the video in this post, I strongly recommend you go through the 4 step Stairway to Extended Events by Erin Stellato (b|t).  I’m just now starting my journey with XE so I will be leaving out everything but the most basics steps I used…this is a 101 post after all 🙂

Please forgive the watermark…was testing Camtasia.  I’ll be buying a copy soon!

I also want to thank Dave Mason (b|t) for his post Hide and Seek with Extended Events, which helped me understand why I was not seeing my test data in “Watch Live Data” mode, and come up with the workaround you see in the video.  Dave has his own workaround that I did not test.  Lastly, thanks to my Apprentice DBA (t) for teaching me XE after I had him go learn from the Stairway and some testing on his own.   I used what he taught me the next day to capture a sample command on a production system so I could tune some code in the customer’s test environment.

Thanks for reading!

Kevin3NF

Follow @Dallas_DBAs


Filed Under: Beginner, EntryLevel, Performance Tuning, video

T-SQL Tuesday: Giving Back

May 8, 2018 by Kevin3NF 2 Comments

T-SQL Tuesday is a monthly blog party for the SQL Server community. It is the brainchild of Adam Machanic (b|t) and this month’s edition is hosted by Riley Major (b|t) who has challenged us to “Pick some way you can help our community“…but not just give a few sentences on how you want to help, but to actually put feet, brain cells and dates to it.

Community service is something I’ve been involved in for decades in many different ways.  Within the SQL Server specific community, I got serious about it a couple of years ago when I changed the nature of this blog from “weird stuff I saw at work today” to “here is some info you can use to make your life better today.”  I also started speaking at SQL Saturdays last June in Houston.

Last year, I decided to take this a step further and set up an unofficial “Apprentice” program to help young people get into tech careers that don’t (for whatever reason) have the same opportunities most of us do.   My barrier to entry was low…others not so much.

The 1st Apprentice is ready to become a part-time Junior DBA and I couldn’t be more proud of him for his hard work.  He entered the program as a bit of a test case.  His barrier to entry – zero desire to go to a 4-year school and chase a possibly useless (for him) degree.

I will soon be looking for the next Apprentice.  Will s/he be like the first?  Maybe from a low income area?   Possibly aging out of the Foster Care system?  On the Autism spectrum?  Who knows.

For now, I will be working with one at a time.  I would like to get to the point where I have 2 or 3 that can learn together by working out solutions as a team.   This will help them not only learn Database Administration, but teamwork, trust, communication skills, etc.  Some of them may decide they hate databases but think Security is really cool.  Or Python.  Or Networking.  And that is great!  If they can find a career that they enjoy and provides a stable lifestyle financially, then I’m thrilled to be a step along a glorious path for them.

HOW YOU CAN HELP!

As these young people get to the point that I run out of things to teach them, they need real-world practice. Eventually I will have an “Apprentice” rate/offering on my Services and Pricing page for them to do the grunt work on your servers.  Part-time, with oversight from me or another Sr. Level DBA.  There are caveats and conditions on this I have not sorted out yet, but its coming sometime in the next 6-12 months.  Please keep an eye out for my posts here, on Twitter and on the Dallas DBAs LinkedIn Page.

I want your thoughts on this…privately or in the comments as you see fit.

Thanks for reading,

Kevin3NF

 

Filed Under: Apprentice, Beginner, Career, EntryLevel, Training, TSQL2sday

TSQL Tuesday #100: Looking to the future

March 13, 2018 by Kevin3NF 3 Comments

 

100 months from now:

Auto-Shrink finally removed from SQL Server source code.

Filed Under: Beginner, TSQL2sday

SQL Server backups to Azure Blob storage

January 16, 2018 by Kevin3NF 15 Comments

My Pluralsight course for new SQL Server DBAs

 

This is an intro level post, specifically written for the new and accidental DBAs that have been told to direct their SQL Server backups to Azure storage…but without any additional information.  It does not include discussions around backup types, recovery models, etc.  Those are all great topics that are very well documented elsewhere.  Also useful for veteran DBAs (like me) that suddenly have to sort out cloud technology.

Enough of that…

If you like to watch videos to learn new technology, I offer this.  Otherwise scroll on down for text and screenshots, with code samples:

 

Basic terminology:

  • Azure – Microsoft’s Cloud offering. We aren’t talking about AWS or Google today.
  • Subscription – an account to create and use Azure resources
  • Resource Group – a logical container for grouping like-purpose resources
  • Resource – anything in Azure you can create, such as SQL Databases, Virtual Machines, Storage accounts, etc.
  • Storage account – loosely similar to a Fileshare…created to hold a specific type of items
  • Container – a sub-group within a storage account – roughly similar to a folder on a fileshare
  • Access key – a code you need in order to access a Storage account
  • URL – the location specific to the container you have created
  • SQL Credential – created at the SQL instance – uses the access key to allow backups to go into containers. The credential is specified in a backup or restore statement.

What we are going to do:

  • Create a storage account of Kind “Storage”
  • Create a container – “Blob Service”
  • Create a SQL Server credential
  • Create a new SQL Database on my 2016 instance
  • Backup the database to the new container
  • Restore that backup to a new database name
  • All of this in T-SQL, because the SSMS GUI is cumbersome

Assumptions:

  • You already have an Azure account/subscription
  • You already have a test SQL instance, SQL 2012, SP1, CU2 or higher.
  • You are an amazing and wonderful person
  • You know the basics of SQL Server backups and recovery models
  • You are going to follow me on Twitter
  • You are interested in being even more awesome at your job than you already are

Start with the Azure part:

Log into your subscription and click Storage accounts on the left side, then click +Add:

Select the properties for your new storage account.

Account Kind: Storage or StorageV2, not Blob Storage

Performance: Standard vs. Premium is spinning disks vs. SSD…Standard for testing or infrequently accessed files.

Replication: research and choose wisely

Resource group: where will this storage account go?  Just a logical container

Location: probably a good idea to keep it fairly close to the SQL Servers you are backing up for performance reasons…but you may want to send it farther away…your call.

Click Create and wait for the notification to let you know the account exists.

Go back to the storage accounts blade and refresh to see your new account.  Click it.

Verify the settings you chose are there (highlights below):

Click on ‘Access Keys’ to see the two auto-generated Keys and Connection strings for accessing this storage account.  Do not give these out freely…only to those with a need for them.  If they get out, you can regenerate either one or both pairs.   You will need one of the 2 keys when we create a SQL Server Credential later on.

Click ‘Containers’ under Blob Service

Click + Container and give it a name.  Names can only be lowercase letters, numbers and hyphens.  If you enter an illegal name it will not let you continue.  I use the SQL instance name here, just as I would for a regular folder on a files hare.  Also, choose Private for the Public Access Level.  Click OK to create the container.

Enter the name here:

The deployment of the container should be very quick.  Click on its name to open it:

Note the “no blobs found” in the container.  After a successful backup, you will see it here.

Click on ‘Container Properties’ to get the URL for this specific container…this will be used in Backup and Restore statements.  Click the button next to the URL to copy it.  For now just remember where this is or copy it to Notepad, Query window etc.  When we start to build our T-SQL statements, we will need both the Access key from earlier and the URL.

At this point, you have an Azure Subscription, with a Standard Storage Account, that has a Blob Container in it.  For now, that is all we will do in the portal, but leave your browser open for copying the Key and URL, as well as refreshing to see results of the Backup command.

Now for the SQL Server part:

Open SQL Server Management Studio.   I am using 16.x despite 17.4 being out as of this writing, mostly because I upgrade slowly and don’t like the icons of the 17.x releases.  I am using SQL Server 2016 Developer Edition on a Windows 10 Pro Dell Precision laptop.

Create a SQL Server Credential

Note that I have no Credentials at this time:

Go to your portal, and copy one of the Access Keys associated with your new Storage Account.


USE master
GO
CREATE CREDENTIAL SQLBackups --give this a meaningful name
--storage account name:
WITH IDENTITY='sqlbackups12345',
--storage account key from portal:
SECRET = 'pvv99UFQvuLadBEb7ClZhRsf9zE8/OA9B9E2ZV2kuoDXu7hy0YA5OTgr89tEAqZygH+3ckJQzk8a4+mpmjN7Lg=='
GO

Run this in a Query Window, using the Storage Account name and Key from your subscription.

Refresh the Credentials in SSMS and verify the new one was created:

If you don’t already have database you want to backup (you should be doing this on a test system…), create one:


-- Create a test database
-- minimal options for demo...don't create
-- your databases like this

Create Database Test

 

Now, the whole point of all this…create a Backup Database command:

The ‘TO URL’ replaces the ‘TO DISK’ you are used to.   It includes the URL from the portal for the container as well as the name of the file you are creating.   Also, the WITH CREDENTIAL is new:


--back it up to Azure
--get URL from portal, add database name-date to the end of the URL

BACKUP DATABASE Test
TO URL = N'https://sqlbackups12345.blob.core.windows.net/kbh-precision-2016/Test_20180114_1038am.bak'
WITH credential = 'SQLBackups';
GO

-- go see the file in the portal

If your Backup created successfully, go to the Container in the Portal and refresh:

To RESTORE the database from the Blob backup you just created, use the same URL and Credential:


-- Restore the DB to a new DB:
--use the same URL as above
-- WITH Moves to new file names

RESTORE DATABASE Test_restored --new database name
FROM URL = 'https://sqlbackups12345.blob.core.windows.net/kbh-precision-2016/Test_20180114_1038am.bak'
WITH CREDENTIAL = 'SQLBackups',
Move 'test' to 'C:\Program Files\Microsoft SQL Server\MSSQL13.SQL2016\MSSQL\DATA\Test_Restored.mdf',
Move 'test_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL13.SQL2016\MSSQL\DATA\Test_Restored.ldf'
;
GO

And refresh the SSMS Database list:

That’s it…the basics and minimums.  You can of course add other normal Options, such as STATS and COMPRESSION.

Edit…when I wrote this, I was not aware of a decent way to clear out files beyond a certain number of days.

Messing around with a PowerShell script I found, I got this:


#Script to delete backup files

# Set variables
$container="yourcontainername"
$StorageAccountName="YourStorageAccountName"
$StorageAccountKey="YourStorageAccountAccessKey"
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$retentiondate = Get-Date

# read the list of files from the container
$filelist = Get-AzureStorageBlob -Container $container -Context $context #-Blob *trn

foreach ($file in $filelist | Where-Object {$_.LastModified.DateTime -lt (($retentiondate.ToUniversalTime().AddDays(-7)))})
{
$removefile = $file.Name
if ($removefile -ne $null)
{
Write-Host "Removing file $removefile"
Remove-AzureStorageBlob -Blob $removeFile -Container $container -Context $context
}
}

Works on a VERY limited test on my system.  You can change the retention in the AddDays.  I had to add .ToUniversalTime to mine as PowerShell was reading the blobs as UTC/zulu and not deleting based on US Central.

If you have any other questions, feel free to ask in the comments.  If you get specific errors in the BACKUP or RESTORE commands, head off to Google first is your fastest choice.

Edit 2: Don’t use the VERIFY option if you are backing up to Azure directly…read this on why that can be an expensive option

Thanks for reading!

Kevin3NF

My Pluralsight course for new SQL Server DBAs

Follow @Dallas_DBAs

Filed Under: Azure, backup, Beginner, EntryLevel

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 5
  • Go to page 6
  • Go to page 7
  • Go to page 8
  • Go to page 9
  • Interim pages omitted …
  • Go to page 13
  • Go to Next Page »

Primary Sidebar

Search

Sign up for blogs, DBA availability and more!

Home Blog About Privacy Policy
  • Home-draft
  • Blog
  • About Us

Copyright © 2026 · WordPress · Log in

 

Loading Comments...