Tag: syndicated

  • Changing the Owner of a Database #SQLNewBlogger

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

    I had an authorization issue with my account, and I decided to delete it and re-add it. That’s the subject for another day, but before I could delete it, I had to remove the ownership of some databases. You can’t delete a login that owns databases.

    I realized I wasn’t sure how to do this, so I wrote this post.

    A Deprecated Proc

    There used to be a dbo.sp_changedbowner proc that was used, but I know this is deprecated and it shouldn’t be used. It likely would work fine in SQL Server 2019, but I also know there should be more modern code. I decided to look, as I ought to know what is recommended these days.

    In searching around MS Docs, ALTER AUTHORIZATION comes up in the list. I checked, and this allows me to transfer the ownership of a securable, which a database is one of the items in the list. Example F shows what I want to do and uses this code:

    ALTER AUTHORIZATION ON DATABASE::dbname TO [login]

    I can replace dbname and login with the values I need.

    Which Databases?

    I have a lot of databases, and I don’t need to change them all, though I could. In my case, I decided to get a list of databases and owners. If you query sys.databases, there is an owner_sid column. If you join that with sys.server_principals, you can do so on the SID column. This query shows me what I need:

    SELECT d.[name], sp.[name] FROM sys.databases d
      INNER JOIN sys.server_principals AS sp
       ON d.owner_sid = sp.sid

    The results are here:

    2022-02-25 12_34_10-SQLQuery1.sql - ARISTOTLE_SQL2017.master (sa (54))_ - Microsoft SQL Server Manag

    In some sense I hate that “sa” isn’t the default owner, but I get it. There might be a need for other accounts. However, my account is a sysadmin, so my view here is that “sa” ought to be listed.

    I digress. Now that I have a list, I can limit it to my account with a WHERE clause. I can take that list of items and build the code. I could use a cursor, but this is a one-off task, so this works:

    SELECT
                    'ALTER AUTHORIZATION ON database::' + d.[name] + ' TO sa;'
                  , d.[name]
                  , sp.[name]
    FROM
                    sys.databases d
         INNER JOIN sys.server_principals AS sp
             ON d.owner_sid = sp.sid
    WHERE          sp.name = 'ARISTOTLE\Steve';
    GO

    This gives me the code in the results I want to run. I copy paste this and I have a bunch of statements to run. 

    2022-02-25 12_41_07-SQLQuery1.sql - ARISTOTLE_SQL2017.master (sa (54))_ - Microsoft SQL Server Manag

    Despite Grammarly not being happy, this worked fine.

    SQL New Blogger

    As soon as I realized I needed to do this, I knew there were two posts here. One on the removal and adding back of my Windows account, and the second on this topic (when the first didn’t work).

    This took about 15 minutes extra, finding the docs and writing some code, but it’s a good example of where a small situation that occurred helped me find something to write about. Easy for you to take little tasks like this and document your knowledge when you learn something.

  • Daily Coping 14 Mar 2022

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to take three calming breaths at regular intervals during the day.

    This is an easy one for me. Since I’ve been practicing yoga for 10-12 years, I often find myself taking more conscious breaths at times. Fill up deeply, hold briefly, and slowly let them out.

    It’s amazing how calming 3-4 deep breaths can be.

  • Daily Coping 11 Mar 2022

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to start today appreciating your body and health and the fact you are alive.

    I do this often. I’m in the midst of working to lose some weight and get healthier. This is a slightly stressful place as I have an appointment scheduled to re-test my blood in a week or so.

    However, every day I can go to the gym, I can practice yoga or lift weights, I’m grateful. Each time I think about the things I want to change, I think about how lucky I am to not have any major chronic issues.

    Maybe not every time, but many times. I do think that I am lucky to not have had any major health issues, and I survived COVID (twice) without long term effects. I’m also fairly healthy, fit, and happy to be alive.

  • ETL v ELT

    This is part of a series on my preparation for the DP-900 exam. This is the Microsoft Azure Data Fundamentals, part of a number of certification paths. You can read various posts I’ve created as part of this learning experience.

    I don’t have an ELT tag, and I’m not likely to make one. I tend to think of ETL as loading data somewhere, even though I know it means more.

    The important concepts for DP-900 here are that ELT is becoming more important and you need to understand what this means. I’ll cover these concepts, but also give a little overlap with where the different Azure services fit in with this.

    ETL

    For most of my career, the pattern for loading data was Extract-Transform-Load. In this pattern we:

    • grab data from a source
    • make changes to clean/change/etc.
    • write to a target (or sink)

    It’s how tools like SSIS work. They connect a source to a target and have a bunch of tasks or transforms in the middle that change the data in some way.

    This is a good pattern for getting the work done when the target system is just built for querying data, such as a data warehouse. It is also good when you need to scrub some data, perhaps for privacy reasons.

    This isn’t a good pattern when you are trying to load data quickly as the transform process takes time.

    ELT

    This is the new way of doing things. I this patter we Extract-Load-Transform, though really, it’s not a pattern that quite makes sense in that the process of moving the data just moves it.

    Here we:

    • grab data from a source
    • write it to a target

    Where’s the transform? Well, that happens on the target, often when someone queries the data. Modern analytic systems, like Snowflake and Synapse, can work with vast quantities of data, often stored in a data lake or blob system, and consume that with powerful computational capabilities. There could be some minor re-shaping of the data on write, but that’s not the idea.

    This is good when you might not read all the data. Why process (transform) what isn’t being read. Before you complain that you should know what is used, none of us know if all our data is being used. Unless we write crappy SELECT * code with no WHERE clauses.

    This is also good when we need to work at speed and privacy isn’t a concern. It’s great for the known formats of files sent to us, as the target system can project a table on top of a ser of files.

    ELT seems to be the current future direction of many analytical and warehouse systems.