Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 1317 | Views in the last 30 days: 15
 
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    
schema    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones