Twitter

Follow SQLQuill on Twitter

Subscribe

MN Pass

October PASSMN Meeting

Meeting Details

Please click here for meeting details and to RSVP

Data Quality Services

Jeff Prom, Magenic

As the old adage goes, ‘Garbage in, garbage out.’ Stop spending hours manually cleansing your data, and start using Data Quality Services! DQS is the new data quality tool provided with SQL Server 2012. In this session we will cover topics such as creating a knowledge base, data cleansing, data matching, and using 3rd party knowledge bases (Reference Data). We will talk about installation, show how to use the DQS tool, the Excel Add-in, and how to integrate DQS into your SSIS packages.

Jeff Prom is a Senior Consultant with Magenic Technologies in Minneapolis. He holds a bachelor’s degree, three SQL Server certifications, and is an active PASS member. Jeff has been working in the IT industry for over 14 years and currently specializes in data and business intelligence.

Ola Hallengren’s SQL Server Maintenance Solution

DBAs are inconstantly using SQL Server standard maintenance and custom maintenance plans to maintain SQL environments. Ola Hallengren has been generous enough to contribute his maintenance plans which are not only effective, but also can be customized to meet small to large SQL environments.  These plans have won SQL Server Magazine 2011 Gold Community Choice and Silver Editors’ Best awards.  The Ola’s maintenance plans cover:

  • SQL Server Backups
  • SQL Server Integrity Checks
  • SQL Server index and Statistics Maintenance

Rizwan Hassan is a Database Administrator with Kroll Ontrack in Eden Prarie. He has been working with SQL Server since 2010.  Rizwan was introduced to SQL Server and mentored by, PASSMN’s Director of Program Development, Tim Plas.

 

Magenic

SQL Saturday #149 – Wrap up

The Highlights:

I was very impressed with the entire event.  Paul Timmerman (T) did an excellent job planning and organizing the entire thing.  Many thanks to all the volunteers who helped as well – too many to list out and I know I would feel bad when I remembered someone I forgot to mention.

I finally got to meet and talk to grrl_geek, SQLMD, WIDBA, DataOgre, and IngeniousSQL.  That was the best part of the day for me.  My one regret is that missed meeting SQLSoldier.

I was also very inspired by meeting Andy Yeager (LinkedIn) – the guy is looking to change careers and he wants to get into the SQL server game, so in his spare time he’s been studying, reading and attending events like this.  In my spare time, I watch football.

My Session:
TSQL Tips and Tricks

Thanks for everyone who attended my session.  It was fun and I was much more comfortable presenting than I have been in the past.  I honestly had fun doing it.  Next time I will project my voice more or use a microphone – that was the most commented on aspect of my talk in the evals. 

Click here to download the presentation with the demos.

Here are the links I mentioned during the session that I would post:

 

SQLSaturday #149–this weekend!

SQL Saturday #149 is coming this Saturday to the U of M campus.  The official site for all the information is here.  Normally I would be supporting Dabo and the Clemson Tigers, GAC or Coach Kill if I were to be on a campus on a Saturday afternoon, but this promises to be as good or better.

I will be presenting my “Beginning TSQL Tips and Tricks” as well as doing “Topics On A Stick: Networking & Mock Interviewing” at lunch time.

Tomorrow I will be checking out the twitter buzz (#SQLSat149) and making sure I’m following all the attendees by using this powershell script.

SQLQuill – Link Round Up – September 2012 Edition

Here’s the links I’ve tweeted in the last month – hope it is useful/entertaining/etc.

SQL

Tools

News

Entertainment

Sports

Sports Humor

Running/Workouts

Constraint Disabling–sometimes it needs to be done

Recently I was trying to reproduce an error in a test environment and I needed to insert data that didn’t fit into the current constraints.  Long story on how it got there, but it was something I had to deal with.  The question someone asked me was could we disable a constraint – instead of dropping it, adding the data, then adding the constraint back without checking the existing data.  It’s pretty simple to do using the NOCHECK clause.  Some legit reasons to use this would be to:

  1. Bulk loaddata
  2. Reproducing errors
  3. Send a team of DBAs on a wild goose chase

To disable a constraint, the TSQL is:

ALTER TABLE dbo.<<TableName>> NOCHECK CONSTRAINT <<ConstraintName>>;

To enable it

ALTER TABLE dbo.<<TableName>> CHECK CONSTRAINT <<ConstraintName>>;

Here’s where I got my info from…
http://msdn.microsoft.com/en-us/library/ms190273.aspx

Don’t Miss a PK in a Delete

Recently, I was tasked with writing a job that would delete data — with a bunch of rules on what could be deleted and what couldn’t.  I thought it was going to be fairly straight forward, but the finer points of the situation made it quite complicated.

The Situation:

The diagram below works as an example of the situation.  Sometimes I needed to delete data from Table1 as well as all other dependent data, sometimes I needed to delete it from Table3, sometimes from Table4, etc.  I wrote the procedures to do delete each set of dependent data, but I was never sure if I had gotten it all – the real life situation wasn’t this linear and sometimes tests would fail and I would add another table to my deletion steps.  I needed a script…

PKExample

The Setup:

I decided to create the situation above and see if I could come up with a script that would identify PKs that would cause my deletions to fail.

Here’s the script:

CREATE TABLE [dbo].[Table1](
[T1ID] [int] NOT NULL,
CONSTRAINT [T1ID_PK] PRIMARY KEY CLUSTERED
(
[T1ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table9](
[T9ID] [int] NOT NULL,
CONSTRAINT [T9ID_PK] PRIMARY KEY CLUSTERED
(
[T9ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table3](
[T3ID] [int] NOT NULL,
[T1ID] [int] NULL,
[T9ID] [int] NULL,
CONSTRAINT [T3ID_PK] PRIMARY KEY CLUSTERED
(
[T3ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table2](
[T2ID] [int] NOT NULL,
[T1ID] [int] NULL,
CONSTRAINT [T2ID_PK] PRIMARY KEY CLUSTERED
(
[T2ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table7](
[T7ID] [int] NOT NULL,
[T3ID] [int] NULL,
CONSTRAINT [T7ID_PK] PRIMARY KEY CLUSTERED
(
[T7ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table6](
[T6ID] [int] NOT NULL,
[T3ID] [int] NULL,
CONSTRAINT [T6ID_PK] PRIMARY KEY CLUSTERED
(
[T6ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table5](
[T5ID] [int] NOT NULL,
[T2ID] [int] NULL,
CONSTRAINT [T5ID_PK] PRIMARY KEY CLUSTERED
(
[T5ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table4](
[T4ID] [int] NOT NULL,
[T2ID] [int] NULL,
CONSTRAINT [T4ID_PK] PRIMARY KEY CLUSTERED
(
[T4ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
CREATE TABLE [dbo].[Table8](
[T8ID] [int] NOT NULL,
[T4ID] [int] NULL,
CONSTRAINT [T8ID_PK] PRIMARY KEY CLUSTERED
(
[T8ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Go
ALTER TABLE [dbo].[Table2]  WITH CHECK ADD  CONSTRAINT [FK_Table2_Table1] FOREIGN KEY([T1ID])
REFERENCES [dbo].[Table1] ([T1ID])
Go
ALTER TABLE [dbo].[Table2] CHECK CONSTRAINT [FK_Table2_Table1]
Go
ALTER TABLE [dbo].[Table3]  WITH CHECK ADD  CONSTRAINT [FK_Table3_Table1] FOREIGN KEY([T1ID])
REFERENCES [dbo].[Table1] ([T1ID])
Go
ALTER TABLE [dbo].[Table3] CHECK CONSTRAINT [FK_Table3_Table1]
Go
ALTER TABLE [dbo].[Table3]  WITH CHECK ADD  CONSTRAINT [FK_Table3_Table9] FOREIGN KEY([T9ID])
REFERENCES [dbo].[Table9] ([T9ID])
Go
ALTER TABLE [dbo].[Table3] CHECK CONSTRAINT [FK_Table3_Table9]
Go
ALTER TABLE [dbo].[Table4]  WITH CHECK ADD  CONSTRAINT [FK_Table4_Table2] FOREIGN KEY([T2ID])
REFERENCES [dbo].[Table2] ([T2ID])
Go
ALTER TABLE [dbo].[Table4] CHECK CONSTRAINT [FK_Table4_Table2]
Go
ALTER TABLE [dbo].[Table5]  WITH CHECK ADD  CONSTRAINT [FK_Table5_Table2] FOREIGN KEY([T2ID])
REFERENCES [dbo].[Table2] ([T2ID])
Go
ALTER TABLE [dbo].[Table5] CHECK CONSTRAINT [FK_Table5_Table2]
Go
ALTER TABLE [dbo].[Table6]  WITH CHECK ADD  CONSTRAINT [FK_Table6_Table3] FOREIGN KEY([T3ID])
REFERENCES [dbo].[Table3] ([T3ID])
Go
ALTER TABLE [dbo].[Table6] CHECK CONSTRAINT [FK_Table6_Table3]
Go
ALTER TABLE [dbo].[Table7]  WITH CHECK ADD  CONSTRAINT [FK_Table7_Table3] FOREIGN KEY([T3ID])
REFERENCES [dbo].[Table3] ([T3ID])
Go
ALTER TABLE [dbo].[Table7] CHECK CONSTRAINT [FK_Table7_Table3]
Go
ALTER TABLE [dbo].[Table8]  WITH CHECK ADD  CONSTRAINT [FK_Table8_Table4] FOREIGN KEY([T4ID])
REFERENCES [dbo].[Table4] ([T4ID])
Go
ALTER TABLE [dbo].[Table8] CHECK CONSTRAINT [FK_Table8_Table4]
Go

The Script:

I looked around the old information super highway and found Pinal Dave (Blog/Twitter) had something that fit into what I was looking for here:

SQL SERVER – Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database

I tweaked it and used the ABCs of CTEs (from Jason Strate (Blog/Twitter) and came up with the following script to identify tables which have primary keys to the initial table, so you will never forget a table in a deletion again :

DECLARE @TableName VARCHAR(255) = 'Table1' --Change this to find the different situations.

;WITH FKStructure  (K_Table, FK_Column, PK_Table, PK_Column, Constraint_Name, Level)
as
(-- Anchor member definition
SELECT
K_Table = FK.TABLE_NAME,
FK_Column = CU.COLUMN_NAME,
PK_Table = PK.TABLE_NAME,
PK_Column = PT.COLUMN_NAME,
Constraint_Name = C.CONSTRAINT_NAME,
1 AS Level
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (SELECT i1.TABLE_NAME, i2.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY') PT ON PT.TABLE_NAME = PK.TABLE_NAME
WHERE PK.TABLE_NAME= @TableName
UNION ALL
-- Recursive member definition
SELECT
K_Table = FK.TABLE_NAME,
FK_Column = CU.COLUMN_NAME,
PK_Table = PK.TABLE_NAME,
PK_Column = PT.COLUMN_NAME,
Constraint_Name = C.CONSTRAINT_NAME,
Level + 1
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (SELECT i1.TABLE_NAME, i2.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
) PT ON PT.TABLE_NAME = PK.TABLE_NAME
JOIN FKStructure FKS on FKS.K_Table = PK.TABLE_NAME)

Select * from FKStructure

SQLQuill – Link Round Up – August 2012 Edition

Here’s the links I’ve tweeted in the last month – hope it is useful/entertaining/etc.  (I’ve been trying out ifttt and sending all my tweeted links to instapaper.com, then exporting exporting it from there)

SQL

Tools

News

Entertainment

Sports

Sports Humor

Running/Workouts

August PASSMN Meeting

Meeting Sponsor:  Digineer

Meeting Details

Please click here for meeting details and to RSVP

MDX Trek: First Contact

Mark Vaillancourt (B/T), Digineer

Cube space; the final frontier. In this Star Trek themed introduction to MDX, we will discuss the fundamentals of cube structure and vocabulary, including tuples, members, sets, hierarchies, and more. We will introduce and demonstrate the basic syntax of MDX with queries that include navigating hierarchies and even some time-based expressions. This session will give you the tools you need to write simple, yet meaningful, MDX queries in your own environment.

SQLQuill – Link Round Up – July 2012 Edition

Here’s the links I’ve tweeted in the last month – hope it is useful/entertaining/etc.

SQL

Tools

News

Entertainment

Sports

Running/Workouts

Sports Humor

July PASSMN Meeting

Sponsored by Magenium Solutions

Magenium Logo High Res

Meeting Details

Please click here for meeting details and to RSVP

O, there’s my data: The Open Data Protocol (OData)

Steve Hughes, Magenic

Earlier this year, Mark Souza from the SQL Server product team spoke at our user group. During the Q&A I asked about interacting better with Oracle. Mark mentioned that OData would be the best way to handle this. I will be discussing what OData is and what tools are involved. I will also explore how to create an OData feed and how to interact with it using tools such as PowerPivot, SSIS, and SQL Azure. I will also examine the impact of OData for data professionals, both good, bad and ugly. In the end, you should understand how OData works and where it can help us expose our data appropriately to our users.

Optimizing Microsoft SQL Server Performance in a Virtual Environment

Denny Cherry, independent consultant

In this session we’ll look over some of the things which you should be looking at within your virtual environment to ensure that you are getting the performance out of it that you should be. This will include how to look for CPU performance issues at the host level. We will also be discussing the Memory Balloon drivers and what they actually do, and how you should be configuring them, and why. We’ll discuss some of the memory sharing technologies which are built into vSphere and Hyper-V and how they relate to SQL Server. Then we will finish up with some storage configuration options to look at.