Author: way0utwest

  • Adding Extended Properties to a Table

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    I had the need recently to get put an extended property on a table in a database. I could easily have done this in SSMS, and have used the GUI before, but since I wanted to make a number of changes for testing, I wanted this done programmatically.

    I knew there had to be an easy way to do this, and was hoping for an ALTER TABLE statement, but that’s not the way it works right now. There’s an sp_addextendedproperty procedure that you can use.

    This procedure is somewhat of a generic procedure that takes a number of parameters, which are used to specify where the extended property applies. There is a name and value of the property, essentially a key-value pair, and then there are 3 levels of properties you can specify.

    Each of the levels has a name and type as well, so this is almost like a hierarchical EAV table. It’s a bit of a mess, IMHO, but that’s OK. It’s nice to have the ability to use Extended Properties for objects, though I wish this were better implemented at different levels and embedded as a core part of your database. The levels are

    • Level0 – Should be used for database scope items. For our purposes, we will use SCHEMA as the type here.
    • Level1 – The next level and should be the type of object getting the property (table, view, procedure, etc.)
    • Level2 – The level that gives the part of the Level1 object, i.e. COLUMN, TRIGGER, etc.

    These will change, and there are some notes on BOL, so be careful and read this before you do much.

    This post looks only at adding a property to a table, so let’s do that.

    I want to add a property to note that a particular table doesn’t need a Primary Key (PK). To do that, I’m going to call my type [PKException] and use a value of 1 to indicate that no PK is expected on this table.

    My call for the procedure will be:

    EXEC sp_updateextendedproperty 
    @name = N'PKException', 
    @value = '1',
    @level0type = N'Schema', @level0name = 'dbo',
    @level1type = N'Table',  @level1name = 'SalesTax3'
    ;
    
    

    In this case, I have a table called “SalesTax3” and it’s in the dbo schema. Those are my values for the Level0 and Level1 parameters. I can ignore the Level2 parameter since I am specifying this as a table level property.

    When I do this, I can then see the property in a few ways, but the easiest for most people is in the table properties, the Extended Properties tab,

    2015-05-26 09_55_09-Table Properties - SalesTax3

    That’s about it. If I want more properties, I can add them by changing the name and value of the property in the code above. I can also change the schema and table if I want this property added to other tables.

    SQLNewBlogger

    This was another side post from a separate post I was writing. I was working on solving a problem and needed an extended property. As I looked up the data to solve my issue and wrote code, I copied the Extended Property code and took a screenshot, leading to this side post.

    Once I had that, this was about 15 minutes to write. I’ll publish this one first, and refer to it in the post that solved my original problem.

    References

    sp_addextendedproperty – https://msdn.microsoft.com/en-us/library/ms180047.aspx

    sys.extendedproperties – https://msdn.microsoft.com/en-us/library/ms177541(v=sql.90).aspx

  • Our Meeting and The Day Out

    Last week, Redgate Software had a large company meeting and our annual Day Out, with myself and a few dozen of our US employees in the UK for meetings and the event. It was fun, and a good time. I haven’t been to a company meeting live in 6 or so years and I’ve never been to a day out, so I was excited to go.

    I was asked to do the opening at the company meeting. Normally our CEO, Simon Galbraith, does an opening and introduces new starters. However with all the US people over, I got to get up first and try to inspire, motivate, and entertain a bit.

    Photo Jun 18, 7 04 46 AM

    Our servery, the canteen where we eat breakfast and lunch was pretty packed on Thursday. I got up and had some fun, showing some images from the ranch of my hard work.

    IMGP4411

    And telling all the youngsters that the worst job in the world was somewhere out there, but not at Redgate.

    worstjob

    I think I motivated people a bit and got them excited about the company. That was part of the meeting, and I truly believe that. Of the 10 or so companies I’ve worked for, this is the best one for a lot of reasons, but mostly because people are respected and get to contribute. We have opportunity and responsibility, and it’s a good mix.

    Afterwards we had a Nerf war in the two story atrium, which delayed a meeting for me, however it was worth it to watch the festivities.

    Photo Jun 18, 8 22 46 AM

    Photo Jun 18, 8 24 15 AM

    Everyone was well armed from the Gun Shop.

    Photo Jun 17, 9 47 41 AM

    The Day Out

    The Day Out is really a teambuilding event. I got out of a taxi at the Cambridge Rugby Club to see all kinds of tents and apparatus set up.

    Photo Jun 19, 8 49 16 AM

    We divided up into teams of 7-8 people and set about competing against each other. We had some mental events, like safe cracking.

    Photo Jun 19, 4 13 50 AM

    Along with a puzzle competition where we had to use the equipment outside the striped tape to get the black box out of the middle, without stepping inside. That was challenging, and with another team trying, we couldn’t do it.

    Photo Jun 19, 4 15 09 AM

    There were physical events as well. We had a sweeper (like on Wipeout) that we competed against and our team tied.

    Photo Jun 19, 4 43 02 AM

    We also had a tug of war, with two of us tied together with a bungee cord. We had to race in opposite directions for about 20-30 ft. and grab a plastic brick from an inflated stand. I have to say that I lost 2/3 chances I had, but I was proud of the one I did win. My competition was a new salesperson, Colin Tanigawa, who just graduated from the University of Washington. He’s 23, and he played football there.

    AP759846241145

    Needless to say, I’m more than twice his age, so I was glad to take one from him. I got to go a second time, as the other team had an extra person, and I raced against a developer. My team leader got a sequence shot of my on the second try, when we broke the bungee. Fortunately I’d won both, so that was that.

    TugWarRace2015

    We had lunch, competed more, in ax throwing, dog agility, and more. All in all, a fun day capped by a BBQ. My wife joined me and we relaxed and chatted with people into the night.

    I had a good time with my team, and my leader, Charlotte, shown below.

    Photo Jun 19, 5 02 16 AM

    I’m hoping to go back again for another day out.

  • Skill Supply and Demand

    Across my career, I’ve seen many managers and executives promote and press for IT groups to consider alternative technologies. The mass media has often promoted new platforms and languages as a more efficient way to build software. Some of their claims might be true, but I think there’s a much bigger factor than technology in how well your software is written.

    Your employees’ skills are probably the most important influence on the quality of your systems. The technology doesn’t matter if the staff doesn’t understand it. I think it’s even more important to be sure that you can replace your staff. People will come and go in your organization.

    I was reading about the development of RavenDB, which is a another platform. It’s written in C#, and the maintainer of the project was asked about moving to F#. His answer, which I found fascinating, was about the supply of F# programmers, both in numbers and cost. There is a lot of debate in the comments, and I find it interesting how differently many people see the world with regards to this issue.

    I think about this as we look at NoSQL platforms, or even other RDBMSes. How easy would it be to dramatically port your software to another data store? Probably not easy, and not inexpensive. The time for training and rewriting code would be very expensive, so much so that it’s often not worth the effort. However the more esoteric your choice of platform, the more difficult it can be to find staff that can even manage your system.

    I don’t think any of the main RDBMSes have a shortage of talented people, but I do think that it can be hard to find employees in some of the NoSQL systems. While I think most smart people could learn a new system, it has to be worth it to your organization to pay someone to learn a new skill.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 2.7MB) podcast or subscribe to the feed at iTunes and LibSyn.

  • I have an ask…

    I heard this quite a bit recently while up in Redmond.

    "I have an ask for you"

    "Do you have an ask?"

    and more. It’s annoying, and disturbing. Hearing that distracts me from the conversation taking place. I keep wanting to say “do you mean you have a request?”

    Even Microsoft employees don’t love it. However, the usage is not necessarily incorrect, which surprises me. And further annoys me.

    I’m sure there’s no way to stop it, but it reads like poor choice of words, picked to seem cool or hip.

    It’s not for me, and it doesn’t encourage me to do anything for you.