Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PowerShell for SQL Server Essentials

You're reading from   PowerShell for SQL Server Essentials Manage and monitor SQL Server administration and application deployment with PowerShell

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781784391492
Length 186 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Donabel Santos Donabel Santos
Author Profile Icon Donabel Santos
Donabel Santos
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Getting Started with PowerShell FREE CHAPTER 2. Using PowerShell with SQL Server 3. Profiling and Configuring SQL Server 4. Basic SQL Server Administration 5. Querying SQL Server with PowerShell 6. Monitoring and Automating SQL Server A. Implementing Reusability with Functions and Modules Index

Scripting database objects


Being able to script database objects is a powerful capability. There may be times when you'll need to have scripts handy, whether for versioning purposes or simply to provide them to your developers.

SMO largely drives this scripting capability. There is a class called Microsoft.SqlServer.Management.Smo.Scripter, which can be passed a collection of SMO objects to script:

$script.Script($smoObjects)

For example, if you need to script all stored procedures, you can add all the stored procedures into an array and pass this array to the Scripter object. You need to ensure that you are passing the actual stored procedure object and not just the names.

The Scripter object also accepts ScriptingOptions. There are a number of options that can be set. They include the following options:

  • DriAll

  • DriIndexes

  • DriNonClustered

  • DriPrimaryKey

  • DriUniqueKeys

  • Encoding

  • SchemaQualify

  • ScriptDrops

  • ScriptOwner

Note

The complete documentation for all properties that can be set using the ScriptingOptions...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image