Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Auto dump out database schema

By Neil Bryan,

This is a PowerShell script that can be used to dump out a database schema to a text file (similar to the Generate Scripts option in SSMS).

I wrote it to dump out out live DB schemas which are not under source control (our dev schemas are).

We run the scripts once a week.

They are very useful when someone accidently overwrites say a stored procedure on the live server.

To run from the command line...

Powershell.exe -File "C:\PowerShell\Output_Schema.ps1" - $SQLInstance localhost\sqlexpress - $Output_Folder_Name "D:\Reports\Schema Dumps" - $Database Accounts_Database
In this example, the above script (Output_Schema.ps1) is placed in the folder c:\PowerShell the output text file is written to the folder D:\Reports\Schema Dumps and the database to use is Accounts_Database.
NOTE: The database parameter is optional, if omitted, then all databases on the server will documented.
A text file per database is generated.

Total article views: 1518 | Views in the last 30 days: 2
 
Related Articles
FORUM

Generate output and place in a specific folder

Generate output and place in a specific folder

FORUM

Script to create datestamp folder causing issue

Script to create datestamp folder causing issue

FORUM

Database schema

Database schema

FORUM

How to sync database schema from a database to another?

sync database design, database schema

FORUM

Schema versus Database

Schema versus Database

Tags
powershell    
schemas    
 
Contribute