Tag: syndicated

  • Moving Objects to a New Schema

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

    I haven’t had the need to move an object from one schema to another in years. Really since SQL Server 2000. I wrote about deleting a user that owns a schema recently, but that’s often a first step. The next thing I might need to do is actually move objects from that schema to a new one.

    I actually ran across this command when I was looking how to move the schema to a new user. There’s actually a parameter for ALTER SCHEMA that will move objects. This is the TRANSFER argument and it works like this.

    I need a new schema for the object. In this case, I’ve got a table called SallyDev.Class. I want to move this to a new schema, and I’ll choose dbo for this example. I often have had developers build in their own schema and then I’ll transfer to the dbo schema, which is almost like a merge of code from one branch (SallyDev) to another (dbo).

    The format of the command is: ALTER SCHEMA <newschema> TRANSFER <object>

    The new schema name is just the name, with brackets if needed. Hint, if you need brackets, rename your schema, please.

    The object is the qualified name of the object, with the old schema. In this case, the command I’ll use is:

    ALTER SCHEMA dbo TRANSFER SallyDev.Class

    Here’s my before look:

    2018-09-17 19_12_02-SQLQuery1.sql - dkrSpectre_sql2017.sandbox (DKRSPECTRE_way0u (68))_ - Microsoft

    When I run the code, it works:

    2018-09-17 19_13_03-SQLQuery1.sql - dkrSpectre_sql2017.sandbox (DKRSPECTRE_way0u (68))_ - Microsoft

    Now my object is moved. Success!

    2018-09-17 19_11_37-SQLQuery1.sql - dkrSpectre_sql2017.sandbox (DKRSPECTRE_way0u (68))_ - Microsoft

    SQLNewBlogger

    This is a quick view of a specific skill that can be handy. I won’t use this often, but if my team worked in this flow, or we had an issue, this not only shows how to resolve a single item move, but also helps me remember the command. I hadn’t seen this before, so a quick 10 minute blog is useful.

    This also gives me ideas for other blogs, like how to automate this for a number of objects.

  • What is Projectsv13 in SQL Change Automation?

    I got this question recently from someone that was evaluating the SQL Change Automation client in Visual Studio. After setting up a new PoC (Proof of Concept), they were confused about why there is a new entry in their list of SQL Servers.

    If you’re wondering, this is what you see in Visual Studio 2017, for the SQL Server Object Explorer.

    2018-09-18 20_20_30-SQLBuilds - Microsoft Visual Studio

    In my case, I’ve actually got a few different instances since I’ve been working with the SQL Change Automation (SCA) for years, across a few versions.

    As the instance names list, these are LocalDB instances. LocalDB is a version of SQL Server that is spun up in process, rather than a service. Other than that, it’s a real SQL Server instance that is running. In fact, if you want, you can connect to this with SSMS.

    2018-09-18 20_22_31-Connect to Database Engine

    If I connect with those credentials, this will appear in the SSMS Object Explorer as well, the same as any other instance.

    2018-09-18 20_22_48-SQLQuery3.sql - dkrSpectre_sql2017.sandbox (DKRSPECTRE_way0u (69))_ - Microsoft

    Why is this in SCA?

    As an early part of the SCA product, when it was in ReadyRoll, there was a desire to not impose burdens on application developers. If you were working with a project for C# or ASP.NET and wanted to include the database, the idea was to keep things simple.

    The simple way to get up and running is to use LocalDB, so no install, no worries with Express and a service running, just use LocalDB. This used to be more of a default, but now it’s just one of the options.

    In my case, once I’ve setup my project to connect, the Shadow database, by default, is also right here, and I’ll see both databases under the (localdb)\Projectsv13 instance.

    2018-09-18 20_27_51-SQLBuilds - Microsoft Visual Studio

    All of this is configurable, so you can set things to work in whatever manner works best for you. If you typically have a development instance, either local or remote, you can easily use those instead, and you’ll never need to worry about LocalDB. In fact, if this bothers you, you can disconnect or even delete the instance.

    2018-09-18 20_32_02- 

    LocalDB is a lightweight way to work with SQL Server, but you don’t need to use it.

  • The Trigger Roundup–T-SQL Tuesday #106

    This month was my turn to host T-SQL Tuesday. I chose Trigger Headaches or Happiness as the topic, and I am glad that there have been quite a few responses.

    I started the review almost immediately,and here are a few highlights. I separated these based on how I first thought of them after reading the post. If you think I’ve mischaracterized one, let me know.

    In case you don’t want to add, it’s 9 to 13, so triggers are a headache.

    Helpful Triggers

    I have to start with Burt Wagner, who gets top billing while wearing a Hawaiian Shirt. Thanks, Burt, and interesting solution. In the case where Burt wants to use Temporal Tables in pre-SQL 2016 instances, he uses triggers to manage the history table. I think that’s a great way to use triggers, and while slightly hidden, this should overall work well. The downside is that any schema changes to the table need changes to the trigger and history table, which could be slightly lost if developers don’t realize this.

    The newest evangelist at Redgate is Kendra Little, who loves triggers. Her post looks at her first experience with triggers. It was positive as a way to detect changes for downstream systems.

    Shane O’Neil has written about when triggers are good, talking about the way in which he tracks when new databases appear on his instance, with an email to auditing.

    Aaron Bertrand discusses INSTEAD OF triggers, and gives you the places where these are useful, or even necessary.

    I’ll file this as helpful when Peter Schott writes some code to disable triggers.

    Data migration is always tricky, but Jay Robinson gives a way in which triggers are helpful. I think that this is a great use, and more people ought to do this to simplify deployments and let data migrations occur over time, not all at once.

    Despite his misgivings, I think Marek Masko shows that he uses triggers effectively in code.

    I think Service Broken is amazing, and I wish that messaging and queueing processes were a pattern more of us used. Reid DeWolfe shows how triggers work in conjunction with Service Broker to get things done.

    A simple solution from Eugene Meidinger with the cautions that we need to be very careful with server level triggers.

    Headache Triggers

    Rob Farley has a discussion about some of the problems you can run into with triggers. He likes them, and has written about them before, but he offers advice for how to deal and write triggers in your organization.

    Dave Mason has a post on DDL triggers, which fire in response to event classes. If you’ve never used these, Dave gives you a few ideas on where they might be handy.

    We get a look at the good, bad, and ugly of a trigger in an AG from Bob Pusateri.

    David Fowler has a great post on nested triggers, with Service Broker in between to ensure there is no limit to the number of times the trigger fires.

    Jon Shaulis has a long post that provides an overview of triggers, where they work and don’t, and includes a few ideas for replacing triggers.

    Claudio Silva writes about triggers being hidden and wasting his time.

    I almost can’t believe the number of triggers Allen White has seen on a table, but since I have had similar customers and employers, I’m not surprised.

    Logon triggers can be headaches, and James Livingston shares one of his with us.

    The great Hugo Kornelis gives us a way to use triggers effectively and not be sad. Vote for a suggestion to make them more visible in SSMS. I voted, and I agree. We need better visibility.

    While Eduardo Pivaral writes about good and bad triggers, I think he feels triggers are somewhat bad overall. Certainly his “good fix” might not have been the best choice in his eyes, even though it worked.

    Not realizing that a trigger needs to operate on a number of records is a common mistake, so I’m putting Brian Dudley’s post in this area.

    I’d say that trigger anti-patterns fall into the headache area, and we get a few situations from Nate Johnson.

    Matthew McGiffen tells about the trouble with triggers. As with many of the other posts, he finds that triggers might be worth less than we initially think.

  • A Summit Contest for registering by Sept 22

    If you haven’t registered for the 2018 PASS Summit and plan to go, you might press to get registration done this week. Next week prices increase, but this week you can save.

    passpromo

    There is a promotion from PASS that will let you save $200 this week. In addition, you can beat the price increase next week, which will go up $200, so if you can register by Sept 22, you save $400 over the cost next week. Use the discount code in the graphic above.

    There’s also the chance to win a daily prize from PASSStuff.com. Plus, everyone registering this week will be entered for the chance to win a complementary admission to the 2019 Summit.

    If you’re going to the Summit, or have asked, press to get registration done this week. You’ll save some money and get the chance to win some fun SAWG and maybe even get next year’s summit registration for free.

    Register today and good luck.