Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a memory-optimized table


In this recipe, we will create a memory-optimized table in SQL Server.

Getting ready

Memory-optimized tables require SQL Server Developer and the Enterprise or Evaluation edition.

How to do it...

Let's take a look at the steps to create a memory-optimized table:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module and create a new SMO Server object as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
    
    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
  3. Add the following script and run it:

    $databaseName = "MemoryOptimizedDB"
    
    #for this recipe only
    #drop if it exists
    if($server.Databases[$databaseName])
    {
        $server.KillDatabase($databaseName)
    }
    
    $db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database -ArgumentList $server, $databaseName
    $db.Create()
    
    #Add memory optimized filegroup
    $filegroupName = "MemoryOptimizedData"
    $fg = New-Object...