Category: Blog

  • Delete an Azure SQL Database from PowerShell

    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’ve been working on is trying to get my DevOps, continuous delivery pipeline working with Azure. Part of that is a test deployment to an Azure SQL Database, which means I need to be able to update an existing database from a backup. Unfortunately, Azure SQL Database doesn’t support a restore over an existing database (yet).

    That means one task I have is to remove an existing database, in order to replace it with a new database with the same name. A little work in the PoSh documentation found Remove-AzureRMSQLDatabase, which is just what I need.

    To use this cmdlet, I need a connection to the Azure space first. I can do that with a credential that I get with this command. Ultimately I need to store this, but interactively this lets me get started:

    Login-AzureRMAccount

    This gets me an interactive login. I enter my account and password. Since I use a Live account, this won’t work in the pipeline, but it gets me going.

    2017-03-10 09_00_34-Sign in to your account

    From here, I can set a few variables I’ll need. I want the name of a resource group, a server, and a database. In my case, I’ll use a few variables. I call the database the “new” one, since I’ll be using an existing one that I’ll recreate from an “old” one.

    2017-03-10 09_03_07-powershell - How to Login without prompt_ - Stack Overflow

    From here, it’s just a question of calling the Remove-AzureRmSqlDatabase cmdlet with parameters. I do that, and get results. Here’s the call

    Remove-AzureRmSqlDatabase -ServerName $server -ResourceGroupName $rgname -DatabaseName $newname

    Here are the results. I’ve blacked out a few ids.

    2017-03-10 09_05_16-Photos

    This clears the database, and after refreshing, I can see it’s gone from my list of Azure SQL Databases.

    2017-03-10 09_08_12-SQL databases - Microsoft Azure

    Not much to this, but it’s part of a larger scheme, which is getting a copy of the production database and restoring it.

  • Building a Database DevOps Process at the Data Platform Summit 2017

    I’m heading to India this August for the Data Platform Summit 2017. I am honored to have been selected to deliver a pre-conference seminar called “Building a Database DevOps Process”, where I’ll walk through the way in which you can include your database alongside application code and deploy it smoothly to various other environments, such as test, QA, UAT, Beta, Staging, Pre-prod, etc.

    DPS2017_Logo_Website

    If you are going to be in Bangalore during the middle of August, register for the DPS and come see my, or another, pre con as well. There are some great ones.

    This will be my first trip to India and I’m looking forward to it. Actually my whole family is looking forward, as I’ll be taking a week or so vacation before the conference to travel with them before I spend a week at work. I should be acclimated to the time change by the time the conference starts, which is good. I’ve got customer training also scheduled, so a busy August for me.

    Now to get a Visa and inoculations. Hope to see you there.

  • SQL Bits in less than a month

    I’m getting excited, and you should as well. Join me at a fantastic conference in the UK this spring. Register today and come to a training day and learn something. I might just see you there, as I’m thinking to take one or two myself.

    I’ll be presenting “Including Your Database in a DevOps CI/CD Process” on Friday. I’ll be looking at how you can deal with the challenges of database code in a software development process.

    There are lots of great sessions, and whether you come for 1 or 2 training days, just the Friday sessions, or on the free Saturday even, this is my favorite SQL Server conference and I’m sure you’ll find it to be an amazing event.

  • Global v Session Trace Flags

    I wrote a short article on enabling and disabling trace flags. You can read it, but I didn’t really discuss the implications of session v global trace flags, which is something I’d like to do here.

    In the article, I set trace flag 3226 for my session. This showed that a second backup wasn’t in the error log. Note the image below doesn’t have a backup message after (above) the trace flag change entry. You’ll have to trust me that I ran the backup, enabled the traceflag, and then re-ran the backup to get this image.

    2017-03-02 11_54_50-Log File Viewer - ._sql2014

    However, if I have a backup job, as I do here, does the trace flag affect this? This is, after all, run by SQL Agent, which would be a different session.

    2017-03-02 12_36_08-Job Step Properties - backup

    It turns out that the session trace flag doesn’t affect this. I ran the backup job and there was a message in the error log.

    2017-03-02 11_56_19-Log File Viewer - ._sql2014

    To suppress this, I’d have to use DBCC TRACEON (3226, –1) or put this in the startup parameters to ensure none of these messages appear.