Category: Blog

  • 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.

  • 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.

  • The Company Meeting

    I’m leaving today for a trip to Cambridge, UK. I do this 2-3 times a year, but this one is a little different. I’m being joined by most of my American colleagues at Redgate, all of whom are being flown over to attend a company meeting and a company day out on Friday. It’s one of the rare chances, and quite possibly the only one that will happen again, to get everyone together in the company.

    It’s an expense, arguably an unnecessary one, but it’s also a treat. Spouses and partners have been invited to come along and participate in some fun on Friday. It’s something that stands out in my mind, and it solidifies that Redgate is a great company.

    It’s the kind of company I’d want to build, and it’s run as I’d want to run a company.

    That might be the highest complement I can pay to an employer. They run a company as I would want to do so. They treat people fairly. They treat people with respect. They try to treat customers well, as well as participate in the community. The company is not perfect, but they acknowledge mistakes and try to do better. They work to make a profit, but profit isn’t the most important thing. Perhaps best of all, the management work alongside employees and set good examples. They don’t treat themselves as above or more important than the other employees.

    I’ve worked at a lot of companies in my career, and almost none of them have been companies that I thought were well run with respect for employees balanced with the profit motive and participation in the community. Most were unbalanced in some way, often with respect to profit meaning much more than individuals.

    I’m proud to work at Redgate and am looking forward to the trip with my wife, and a nice weekend in Dublin.