Databases Reference
In-Depth Information
prefix of the filename is generated based on the database name that is passed as the parameter plus the
word '' view ''. The suffix of the filename is generated based on the current timestamp when the script
was executed (see Figure 21-5).
Figure 21-5
Scripting Stored Procedures
The next script, C:\DBAScripts\Script-SP.ps1 , generates all the stored procedures in the database. This
script is similar to the Script-DB.ps1 script. It uses the foreach loop to iterate through all the stored
procedures available on the database and generates the scripts for each one using the script method.
Here, we also use the PreFetchObject method. The PreFetchObject method enables collections to be
fully populated with objects with one network trip to the instance of Microsoft SQL Server. Prefetching
is an optimization used when the whole collection of objects is required.
# ===========================================================
#
# NAME: Script-SP.ps1
#
# AUTHOR: Yan and MAK
# DATE : 5/1/2008
#
# COMMENT: This script generates DDL statement for all stored procedures
#
# ===========================================================
Search WWH ::




Custom Search