Tag: syndicated

  • Finding Objects in a Schema #SQLNewblogger

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

    One of the things I needed to do recently was move some objects from one schema to another. I wrote about moving an object between schemas recently, but another part of that process was finding  the objects to move.

    This is a quick post on how to find the objects in a schema. To start, here are a number of objects in a test database.

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

    A schema has a name, which is the way that we would search for related objects. That means I want a parameter for my query, so I’ll start with a variable to store the name. For me, I’ll use a well named variable like this:

    DECLARE @schema VARCHAR(100) = 'SallyDev';

    Now I have a schema name, where do I find schema data? There is a DMV called sys.schemas, which contains a bit of meta data. If I query that, I see this:

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

    I can see my SallyDev schema, so I know I’ll query this DMV.

    The other information I need is the object data, which is in sys.objects. I query that for the various data I want, but I want to limit data by the schema. In sys.objects, there is a schema_id, which is the data I’ll join with from sys.schemas.

    When I do that, I build a query like this:

    DECLARE @schema VARCHAR(100) = 'SallyDev';
    SELECT
            o.type_desc,
            s.name AS 'Schema Name',
            o.name AS 'Object Name',
            o.object_id
    FROM sys.objects o
         INNER JOIN sys.schemas s ON s.schema_id = o.schema_id
    WHERE s.name = @schema;

    I can execute that and I’ll see the objects I need.

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

    SQLNewBlogger

    This was a post related to the one on moving objects and I wrote this write after that one. It was only about 5 minutes longer to put this together, and it gives me a script I can easily search for on my blog if I need to do this task.

    Once again, a quick and easy way to show some skills, practice explaining something, and get some knowledge stored for my own reference.

  • No More Mysterious Truncation

    If you read the Microsoft White Paper on SQL Server 2019, there’s a gem buried on page 17. It mentions a trace flag, which some of you might appreciate.

    Here’s a little repro:

     2018-09-25 15_00_20-SQLQuery1.sql - Plato_SQL2019.Sandbox (PLATO_Steve (65))_ - Microsoft SQL Server

    As you can see, the plee I made has actually been heard. I don’t know if they listened to me, or if the collective complaints over the year grew to the point that this got fixed.

    In any case, thank you, Microsoft. This is a very nice enhancement.

  • Practical Refactoring

    Today I hosted a webinar with Gene Kim (@RealGeneKim) and we had a fantastic discussion. I was slightly star struck since I’ve been reading his work and quoting him for years in talks about Database DevOps. It feels like I got to work with someone really famous, and I’m hoping I didn’t appear too nervous on the webinar.

    In any case, we had a great discussion, and I think you can still register to watch the recording. If not, we should have this on our Redgate YouTube page soon. We discussed the State of DevOps report, and specifically how the findings relate to databases. It was a good discussion, but when we talked testing, we both had some links to ways that we could build better software.

    In my case, I referenced this talk, Practical Refactoring, which I think is great. A bit is the technical approach, but mostly I find the philosophy and freedom that comes with having tests in place to be invaluable.

    This is based on a real project that these consultants worked on. The code is mocked, so don’t get caught up in the actual methods and structure, but think about how you could apply the ideas to your own work. How can you make the code better in a few minutes.

  • SOS to ADS

    When Microsoft announced SQL Operations Studio last year, I wasn’t thrilled. The move to a VS Code shell was less of a concern to me than having a better SSMS toolset. Actually, with VS moving to MacOS, I was hoping we’d get a slimmer, closer VS version of SSMS that allowed add-ins, extensions, and plugins.

    No such luck. We got SQL Operations Studio, which had the unfortunate acronym of SOS. To top it off, I felt this was more of a developer tool, but the name implies a DBA/sysadmin tool. To me this was a tool somewhat lost in its mission.

    Now we have Azure Data Studio, the renamed SOS, which is interesting. I know there are more features than SOS and some additional work coming, but I can’t get too excited. Other than people that want native connections to a server from OSX and Linux and write T-SQL, is this that useful?

    You can download it and see what you think.