TIE Fighters and sys.types: “There’s Too Many of Them!”

19 July, 2010 (08:39) | SQL, T-SQL | By: Mark V

Y-Wing As the Y-Wing pilot in Star Wars: Episode VI – Return of the Jedi proclaimed, sometimes there’s too many of them. He was referring to TIE Fighters during the assault on the second Death Star. I echoed the sentiment while querying the system catalog for a client’s database. I was building the foundation for a data dictionary (at the end of the project, unfortunately) and started by pulling a list of all the fields in the database along with their data types. I was dismayed when my tables returned more records than there were fields. There were too many of them.

To show why this happenned, I will start by creating a simple table.

 

CREATE TABLE dbo.TooManyOfThem

(

      RecordID int NOT NULL

    , RecordName nvarchar(100) NULL

)

 

Notice that I have an nvarchar field in there. It turns out, that was the culprit. Let’s query the system catalog to return the columns from this table along with their associated data types.

SELECT

      o.name AS TableName

    , c.name As ColumnName

    , t.name AS DataTypeName

FROM sys.columns c

INNER JOIN sys.objects o

ON o.object_id = c.object_id

INNER JOIN sys.types t

ON t.system_type_id = c.system_type_id 

WHERE o.name = 'TooManyOfThem'

 

Since my TooManyOfThem table has two columns, I would expect to get two records returned by this query. Here’s is what I get.

TableName            ColumnName      DataTypeName

-------------------- --------------- ------------

TooManyOfThem        RecordID        int

TooManyOfThem        RecordName      nvarchar

TooManyOfThem        RecordName      sysname 

 

(3 row(s) affected)

 

I have a bad feeling about this. These aren’t the results I’m looking for. Are my fields riding single file to hide their numbers?

My RecordName field is showing up more than once. Notice that the second occurrence has DataTypeName of “sysname.” I reached out with my feelings and modified my query to get more fields returned.

SELECT

      o.name AS TableName

    , c.name As ColumnName

    , c.system_type_id AS C_system_type_id

    , c.user_type_id AS C_user_tpe_id

    , t.system_type_id AS T_system_type_id

    , t.user_type_id AS T_user_type_id

    , t.name AS DataTypeName

FROM sys.columns c

INNER JOIN sys.objects o

ON o.object_id = c.object_id

INNER JOIN sys.types t

ON t.system_type_id = c.system_type_id 

WHERE o.name = 'TooManyOfThem'

 

When I run this new query, I get the following results.

TableName            ColumnName      C_system_type_id C_user_tpe_id T_system_type_id T_user_type_id DataTypeName

-------------------- --------------- ---------------- ------------- ---------------- -------------- ------------

TooManyOfThem        RecordID        56               56            56               56             int

TooManyOfThem        RecordName      231              231           231              231            nvarchar

TooManyOfThem        RecordName      231              231           231              256            sysname

 

(3 row(s) affected)

 

We see that in sys.types, the system_type_id of 231 leads to both “nvarchar” and “sysname.” Let’s write a query to return the types whose system_type_id values appear more than once.

SELECT

      system_type_id

    , user_type_id

    , name

FROM sys.types

WHERE system_type_id IN

(

SELECT

      system_type_id

FROM sys.types

GROUP BY system_type_id

HAVING COUNT(*) > 1

)

We get the following results.

system_type_id user_type_id name

-------------- ------------ ---------------

240            128          hierarchyid

240            129          geometry

240            130          geography

231            231          nvarchar

231            256          sysname

 

(5 row(s) affected)

 

As we see, the system_type_id is not unique in sys.types. The user_type_id, however, does not repeat. So, I change my join to the sys.types view from system_type_id to user_type_id.

SELECT

      o.name AS TableName

    , name As ColumnName

    , name AS DataTypeName

FROM sys.columns c

INNER JOIN sys.objects o

ON o.object_id = c.object_id

INNER JOIN sys.types t

ON t.user_type_id = c.user_type_id 

WHERE o.name = 'TooManyOfThem'

 

Now I get the results I’m looking for.

TableName            ColumnName      DataTypeName

-------------------- --------------- ------------

TooManyOfThem        RecordID        int

TooManyOfThem        RecordName      nvarchar

 

(2 row(s) affected)

 

So, the path you choose will certainly affect your destiny. Here’s another path for you: Robot Chicken Star Wars. Seriously. It’s some of the funniest stuff I’ve ever seen.

 

 

 

 

 

July PASSMN Meeting

30 June, 2010 (21:57) | PASS, PASSMN, Professional Development | By: Mark V

Dude! Itzik Ben-Gan… Dig it!

Start Date/Time:
Tuesday, July 20, 2010 5:00 PM

End Date/Time:
Tuesday, July 20, 2010 7:00 PM

Query Tuning Tips with Itzik Ben-Gan

Meeting sponsor: Digineer

Location: 8300 Norman Center Drive, 9th Floor, Bloomington, MN  55437

Live Meeting

·         URL: https://www.livemeeting.com/cc/usergroups/join?id=7DGRT6&role=attend&pw=h*ZR%248%25%2Fd

·         Meeting ID: 7DGRT6

·         Entry Code: h*ZR$8%/d

Agenda:

5:00 –5:15 : Announcements
5:15 –5:25 : Sponsor
5:25 –6:45 : Query Tuning Tips (Itzik)
6:45 –7:00 : Survey Collection and Giveaways

Presentation:

Query Tuning Tips

Given a SQL Server querying problem there’s much that you can do to enable a good performing solution. Tuning involves arranging an optimal physical environment, e.g., by creating supporting indexes, as well as writing the query in a way that it would get an optimal execution plan. Many factors can affect the efficiency of the solution including the availability of indexes, data distribution and density, and others. In different scenarios, a different solution could be the most efficient for the same querying problem. Query tuning could be considered an art. This session will provide various tips to do efficient query tuning and demonstrate those through specific tuning examples.

Itzik Ben-Gan is a Mentor and Co-Founder of Solid Quality Mentors. A SQL Server Microsoft MVP (Most Valuable Professional) since 1999, Itzik has delivered numerous training events around the world focused on T-SQL Querying, Query Tuning and Programming. Itzik is the author of several books including Microsoft SQL Server 2008: T-SQL Fundamentals, Inside Microsoft SQL Server 2008: T-SQL Querying and Inside Microsoft SQL Server 2008: T-SQL Programming. He has written many articles for SQL Server Magazine as well as articles and whitepapers for MSDN. Itzik’s speaking activities include TechEd, DevWeek, SQLPASS, SQL Server Magazine Connections, various user groups around the world, and Solid Quality Mentors’ events to name a few. Itzik is the author of Solid Quality Mentors’ Advanced T-SQL Querying, Programming and Tuning and T-SQL Fundamentals courses along with being a primary resource within the company for their T-SQL related activities..

PASSMN June Meeting: What’s New In SSRS 2008 R2

14 June, 2010 (09:11) | PASS, PASSMN, Presentations, Professional Development, SSRS | By: Mark V

I have been lax in promoting my local SQL users group, so here goes. Oh, by the way, it’s Lara’s fault that I am a SQL Server consultant. Thanks Lara!

June PASSMN Meeting & Newsletter
Sponsored by Magenic

There will be books, shirts and other swag at the end of the meeting!

Location:    8300 Norman Center Drive, 9th Floor, Bloomington, MN  55437
Date:     June 15th, 2010
Time:    3:00 – 5:30

Please click here for meeting details and to RSVP.

Registration has changed with the move from our previous hosting site and you will be required to log into www.sqlpass.org in order to register for our events. If you have any issues with this, please contact support@mnssug.org.

What’s New in SQL Server 2008 R2 Reporting Services

Lara Rubbelke (Twitter | Blog), Microsoft

Amp up your Reporting Services with the many great enhancements in SQL Server 2008 R2. Lara will take you on a tour of all that is new in R2 including collaboration features, new visualizations, rendering enhancements, and new data sources. After this session you will wonder why they call R2 an "interim" release!

Questions for presenters?
If you have any questions you would like our presenter to answer in the meeting, feel free to submit them ahead of time to support@mnssug.org or to any of the board members before the meeting. All question askers will be kept anonymous.

Other News
•       Live Meeting
   o    Beginning in 2010 meeting, you will now be able to join monthly meetings virtually through Live Meeting. This is a great opportunity to stay connected that has been provided to us by PASS.
•       SQL Azure Presentation
   o   Presented by Mike Benkovich at Twin Cities Cloud Computing User Group (TCCCUG)
   o   July 8th, 2010
   o   Click Here for more information
•       PASS Summit 2010
   o    Registration for PASS Summit 2010 is now open. Register for only $1,395 until June 30. Tap into your 2009 or 2010 training budgets to take advantage of the low rate for PASS Summit.

Exam: 70-448 SQL 2008 BI Dev and Maintenance

14 June, 2010 (08:57) | Professional Development | By: Mark V

In conjunction with my professional development plan, on June 1st I took the 70-448 exam: SQL Server 2008 Business Intelligence Development and Maintenance, which I passed. Hazzah!

With most of my SQL Server career involving SSIS and SSRS, I  felt comfortable in those areas. I have only done a little bit of SSAS, so I knew that was where my prep needed focus. I ended up using the Microsoft Press Self-Paced Training Kit as my main preparation tool. I read pretty much all of it, making sure to learn more about SSIS and SSRS tools and techniques I had not played with. For the SSAS areas, I also performed all of the hands on practice exercises. This helped a lot in making up for not having a lot of SSAS experience. Overall, I found this book to be a very good prep tool and would recommend it to others who are looking to take the 70-448 exam. Also, I found the exam had really good balance between SSIS, SSRS, and SSAS. I had heard from colleagues that the 2005 version was not as well balanced.

In passing the exam (by a much better margin than I expected), I accomplished my main goal for taking it: measuring how much I have learned in the BI space. And I picked up a new MCTS cert in the process. Not a bad day.

Now that this exam, and the prep for it, are behind me, I am digging deeper into SQL 2008 R2. I just set up my Windows 7 laptop to dual boot Server 2008 R2. I set up Hyper V and have a VM with SQL Server 2008 R2 installed and configured. Looking forward to digging in. A Sharepoint colleague also sent me the link to the 2010 Information Worker Demonstration and Evaluation Virtual Machine (RTM). I will be using that to play with the new SSRS features of R2 that related to Sharepoint 2010.

Mmmmmmmm….more learning…mmmmmmmm

No Presenting, Please

9 June, 2010 (09:36) | PASS, Presentations, Professional Development | By: Mark V

When I walked into class on the first day of Acting II at the University of New Hampshire, the chalk board at the front of the room was empty except for three words: “No acting, please.” Yeah. This was an acting class. At first, this made no sense to me, but soon it was crystal clear. Our teacher, David Kaye, taught us if you are truly connected to your character and the scene, then “acting” gets in the way. The key is to be so open to your character that you don’t need to act. If your character is terrified, and you are fully committed to what you are doing, then you ARE terrified. This is achieved through researching the material/character/setting and rehearsal: homework. I didn’t know it at the time, but I learned a great deal about presenting in that room.

When I present, I try to keep a conversational tone. I don’t want to talk at my audience. I want to connect with them. If I’ve done my homework and know the material, if I have rehearsed, then I can focus on sharing the material instead of reading it from my slides. Rehearsal also helps you stay comfortable and avoid speaking too fast due to nerves (done that one). It can be hard, but it is totally worth it when your audience sees how relaxed you are and how much fun you are having. This audience comment from an evaluation of a presentation I did shows that this effort makes a difference:

Good presentation skills – like the "breezy" style

Keeping things relaxed also allows me to pepper in some humor here and there. That can help a lot, too. Sitting through overtly serious, monotone presentations can be painful. I don’t want to do that to anyone. Now, for me, planned humor is a real challenge. I did Improvised Comedy in college and it was perfect for me. I can’t tell jokes to save my life; I would be horrid on Last Comic Standing. But, what I can do is come up with one liners off the cuff. That works for me. But whatever works for you, be it funny images in your slide deck or a well timed rubber chicken, try to work some humor into your presentations if you can. It can pay off, as this audience comment shows:

Good sense of humor!!   Very nice presentation.

Another aspect of the “No acting, please” lesson has to do with honesty. If you really commit to your character, then you show the audience that you believe in what you are doing and they are far more likely to come along for the ride. In terms of presenting, for me that means being open about what I know and what I don’t know. Nothing wrecks credibility like making sh!t up. When I don’t know the answer to a question, I am honest about that. But I don’t just say “I don’t know” and move on. If I don’t know, then I make the effort to point them in the right direction or have them contact me afterward so I can try to track down their answer. This helps a lot, in my opinion, as this audience comment shows:

Let us know what he did and did not know about the subject!

Whether I am presenting at clients or at a user group, etc, I try to keep keep the above in mind. The feedback I have gotten from clients has been great. My presentations at the Minnesota chapter of PASS have gone over really well, too, both averaging 4.4 our of 5 on the audience evaluations. This success is not because I have presented humteen million times or because I wear bright yellow pants, but rather because I have a strategy that works for me.

My advice to new presenters is to find a strategy that works for you. If any of the above work for you, do it. If bright yellow pants work for you, wear them. If it helps you to picture your audience in their Fruit of the Looms, go for it (but, take my word for it: don’t stare). Whatever you need to do to keep things relaxed and fun, bring it.  Share what you have to say like you are showing something really cool to a friend. Above all though, don’t force it. No presenting, please.

My PASS Summit Submissions

27 May, 2010 (09:28) | PASS, Professional Development | By: Mark V

Alrighty then. For the first time in my career, I tossed up some submissions for the PASS Summit. Both are topics I have a passion for and I would absolutely LOVE that chance to present either one…or…dare I say…both? Well, here they are. Here’s looking at you, PASS.

Empowering Your Users With Report Models

Who really knows your data better: You or the marketing manager that spends a lot of time tracking sales from yesterday, last week, etc? How much quicker could that marketing manager get the information she needs if she could create her own reports? With the power of Report Models, she could do just that without having to write a single SQL statement. This presentation will discuss how to create, maintain and secure SSRS Report Models. It will also show some tips and tricks learned through real-world experience implementing and supporting report models for clients.

Where Do You Want To Go Tomorrow?

You dress differently for a wedding than you do for baseball game, right? …Right? Even with mundane, everyday tasks like getting dressed, your future destination has an impact on your current behavior. Whether you realize it or not, even the simple act of getting dressed in the morning involves a little planning. Doesn’t your professional future deserve some planning, too? This presentation will discuss the power of Professional Development Plans and the building of your very own brand through blogging, presenting and effective use of social media like Twitter. I will show you how you can use all of the above to take ownership of your future and turn your job into a career.

Professional Development Plans: Turning Your Job Into a Career

17 May, 2010 (09:37) | Professional Development | By: Mark V

This past Thursday, I watched a Live Meeting webcast by Andy Warren (Twitter | Blog) on Building a Comprehensive Professional Development Plan. Thanks to Jorge Segarra (Twitter | Blog) for organizing it. The recording can be found here.

Andy provides a lot of great food for thought and I highly recommend taking time to watch it. I won’t simply regurgitate it all here. But here are a few of the key points I wanted to focus on:

  • No one is going to build your career for you. You have to take ownership of that yourself.
  • Building your career requires resources like time and sometimes money. The key is to find a balance that prevents burnout and makes the best use of the funds you have available.
  • Writing is important. The ability to convey your ideas and share your knowledge well can go a long way toward building your brand.
  • Networking can be a very important part of increasing awareness of your brand. You may even find yourself a good mentor in the process.

At Digineer, the consulting firm I work for, we have formal Professional Development Plans. That is one of the  many aspects I love about Digineer: they want their employees to continue to grow and develop and they provide support in doing just that.

I want to stress that the idea of a PDP is not just for technical folks. In my opinion, one can apply a PDP in pretty much any industry or area of focus.

Before I get into my own PDP, I think it makes sense to explain a bit about what my overall goals are as a person. You will see later that my PDP goals tie in well with my personal goals.

The following poem on Success is actually a very accurate depiction of my general goals for myself in life. I think people who know me well will be able to see my behavior and attitude represented in these lines. This poem is often attributed to Ralph Waldo Emerson; although there is some controversy about that.

Success
Goal
To laugh often and much;
to win the respect of intelligent people 
   and the affection of children;
to earn the appreciation of honest critics 
   and endure the betrayal of false friends;
to appreciate beauty; to find the best in others;
to leave the world a bit better,
   whether by a healthy child,
   a garden patch
   or a redeemed social condition;
to know even one life has breathed easier
   because you have lived.
This is to have succeeded.

My PDP has both short-term and long-term goals. I find it helps if I have some goals that are more immediate so that I can prioritize and keep myself going. I have also taken long term goals and broken them up into component parts as short term goals. That way, my short term goals can essentially provide the roadmap to my long term goals, allowing me to make progress in strides and effectively track that progress.

My most immediate short term goal is to pass the MCTS SQL Server 2008  Business Intelligence Development and Maintenance (70-448) exam by June 30th 2010. I want to point out that the true goal is not merely passing the exam and getting a cert, but rather to learn the material. Taking the exam is merely the measurement of how I have learned that material. And, when all is said and done, certifications certainly don’t hurt. Note: One of the reasons I have June 30th as a deadline is that June 30th also happens to be the deadline for the free retake as part of the Second Shot promotion. I take my first shot on June 1st.

The long term goal I wish to share is a lofty one. The following quote comes from here:

“The MVP Award recognizes exceptional technical community leaders from around the world who voluntarily share their deep, real-world knowledge about Microsoft technologies with others.”

Like with my certification goal above, the credential itself is not the real goal. Rather, it is the measurement of accomplishing my true goals. The MVP jacket is cool, as is the MVP logo you can put on your blog and in your email auto signature; but it’s not about any of that. If I can earn the right to be an MVP, then that means that I have, on a professional level, accomplished many of the the goals I have in life within the SQL community:

  • Win the respect of intelligent people
  • Earn the appreciation of honest critics 
  • Know even one life has breathed easier because I have helped them through my blog, a presentation, twitter, client engagements, etc

My plan for achieving this goal involves several steps, which map to the points gleaned from Andy’s PDP presentation.

I am taking charge of my own career by spending resources improving my knowledge and skills within SQL Server. In addition to reading blogs and attending meetings at my local chapter of PASS (PASSMN), I also attended SQL Saturday Chicago (which was a great means of networking as well a source of quality information). While the registration for the event itself was free, i did incur travel and lodging costs for my time in Chicago. And I have to say my experience was worth every penny and then some.

In terms of writing, I have established the blog you are currently reading. While I don’t post as often as I would like, I am working on that.

In terms of networking, don’t underestimate the power of “social media.” The SQL community on Twitter is remarkable. While many people do use twitter for just inane banter and letting all of their followers know every time they sit down, stand up, go to the bathroom, breathe, etc, the SQL community is a shining example of using Twitter for broadcasting relevant, quality information. I evangelize Twitter within my own area whenever I can. It is through my blog and presenting that I am building my own brand. It is through Twitter that I am building awareness of that brand.

By monitoring the #sqlhelp hash tag on Twitter, I have also had opportunities to help others in the community. That is not only a fantastic way to reach out for help, but also a way to make an impact by helping out someone else.

I am also currently preparing my abstract for a presentation submission for the PASS Summit in November. I have presented at PASSMN a few times and also within Digineer, as well. Presentations can help you to build your brand and are an awesome excuse to dig deeper into a topic that interests you.

All of these steps are the means by which I am attempting to become a technical community leader who shares deep, real-world knowledge about SQL Server with others. Hm…sound familiar?

I agree with Andy that establishing and maintaining a Professional Development Plan is a great way drive your own future. This goes for non-technical folks as well. I believe that a PDP, and the investment of time (and sometimes money) toward achieving the goals within, is a fantastic step toward turning you job into a career.

Clarification on Viewing Report Properties in SSRS 2005/2008

14 May, 2010 (09:52) | SSRS | By: Mark V

I have been to two different presentations on SQL Server 2008 R2 Reporting Services enhancements over the past month or so. In both of those presentations, the presenter said just about these exact words: “Now, you can view a report’s properties without having to run it first.”

I decided to check Microsoft.com to see if official content said the same type of thing. Sure enough, the Introducing Microsoft SQL Server 2008 R2 eBook has the following on page 185:

“Rather than requiring you to open a report first and then navigate to the properties pages,
Report Manager gives you direct access to the report properties from a menu on the report
listing page.“

All three sources are indicating that in versions of SSRS prior to SQL 2008 R2, you have to open/run a report before you can get to its properties in Report Manager. However, not only is it possible to view report properties in 2005 or 2008 Report Manger without running the report first, it is very easy.

Here is my Report Manager for my SQL 2008 instance (2005 is essentially identical).

image

Notice the “Show Details” button in the red rectangle to the right in the image above. Give that a click and your Report Manager will change to the figure below.

image

Click the Properties button shown in the red rectangle to the left of the report in the image above. That will open up the properties of the report. No need to run it first.

Don’t get me wrong, the new Report Manager interface in SQL 2008 R2 is a great improvement with its Sharepoint style drop down lists. I just felt the need to point out that being able to view a report’s properties without running it first is not a “new” feature of SSRS in SQL 2008 R2. You can do it today.

My Top Ten Lessons From SQL Saturday #31 Chicago

19 April, 2010 (11:50) | SQL, SQLSaturday | By: Mark V

I attended SQL Saturday Chicago this weekend. I had an awesome time and attended great sessions. While I got something good out of every one of the sessions, I decided to distill the entire experience into a top ten list with some of the highlights.

SneakersOnWire

10. According to Google Maps, the distance from Grand station on the CTA Blue Line to Navy Pier is 2.1 miles. I learned this after #8 below.

9. According to Google Maps, the distance from Navy Pier to Grand station on the CTA Blue Line is 2.1 miles. I learned this after #8 below.

8. Just like with shrinking databases, the fact that you CAN walk the distance in #10 above and then walk the distance in #9 above (all in under 2 hours, to ensure you will make it back to the airport in time to catch the last shuttle back to the hotel) does not make it a good idea to do so. AND, just like shrinking a database can affect its future performance, the walk mentioned above created soreness that is definitely affecting my current walking performance. But hey, while I was walking I did what anyone else would do: I asked myself, "What would Forrest Gump do?" Keep on goin’ is what. 

7. A good tip from Jeremiah Peschka ( Twitter | Blog ) is to create variables for commonly used strings (like creating new lines, or escaping single quotes) when building dynamic SQL to keep your code as readable as possible.

6. Kevin Kline ( Twitter | Blog ) pointed out that mixing DDL and DML within a stored procedure will cause recompiles, which can add significantly to resource consumption and execution time.

5. If it is a chilly Friday night in April around 8pm and you buy a churro from the little churro hut on Navy Pier, they may just offer you a second one for free as they are closing up anyway. Sweet. A little fuel for #9 above.

4. Before Andrew Karcher’s ( Twitter | Blog ) presentation on MDX, I knew jack about MDX (I could usually spell it properly, but that’s about it). Now, thanks to him, I don’t know jack anymore. Wait. I mean I now understand the basics that were a mystery to me before. Yeah. The second one.

DevilsTower3. Arie Jones ( Twitter | Blog ) pointed out something I had not read concerning SQL Server 2008 R2 Reporting Services. When exporting to multiple worksheets in Excel, R2 allows you to name those worksheets without sacrificing black cats or running off to Devil’s Tower with Richard Dreyfuss. Hazzah to the product team for adding this. Hazzah, I say!

2. When doing Karaoke in a room full of geeks, requesting Barry Manilow’s Copacabana and substituting Weird Al Yankovic’s Star Wars Cantina lyrics can go over well.

1. Wendy Pastrick ( Twitter ), Ted Krueger ( Twitter ), Jes Borland ( Twitter ), and many others worked hard to put on a great SQL Server event. They succeeded quite well, indeed. Thanks so much to all organizers, volunteers, and presenters.

Making Your SSIS Configuration Files More Readable

15 April, 2010 (10:45) | SSIS, XML | By: Mark V

When you first create a configuration file in your Integration Services project, the XML contents of the file are just laid out in one long line. This makes reading and/or modifying this file more challenging than it needs to be.

There is an easy way to format your file to alleviate this issue. In BIDS, go to File/Open/File, as in the image below:

image

Browse to your configuration file and select it to open within BIDS.

My brand new configuration file looks like this image below:

image

You see that the contents are all on one line. Bleh.

To fix that, you can go to Edit/Advanced/Format Document, as shown below:

image

I have done that to my config file and now it looks like this:

image

As you can see, this is much easier to deal with. Just save this document and close it. Now, even when you open it in Notepad, that formatting persists.

image

This little trick can make dealing with your configurations files a bit easier.