O'Reilly logo

SQL Server 2014 with PowerShell v5 Cookbook by Donabel Santos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Altering database properties

This recipe shows you how to change database properties using SMO and PowerShell.

Getting ready

Create a database called TestDB by following the steps in the Creating a database recipe.

Using TestDB, we will perform the following tasks:

  • Change ANSI NULLS Enabled to False
  • Change ANSI PADDING Enabled to False
  • Change compatibility version to 110 (SQL Server 2012)
  • Restrict user access to RESTRICTED_USER
  • Set the database to Read Only

How to do it...

Let's look at the steps involved in altering databases using PowerShell:

  1. Open PowerShell ISE as administrator.
  2. Import the SQLPS module and create a new SMO Server Object:
    #import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required