[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


I simply want to use program to read database structure (schema) and save it into a file to be used to recreate DB structure

Posted on 2014-08-29
Medium Priority
Last Modified: 2014-11-11
I am using asp.net c# and Microsoft SQL

Really my request is quite simple to be able to read database structure, ie tables and relations and stored procedures etc. and store it in a file.  So later I could execute the file and recreate the db in its entirety.  Not talking about data.
Question by:goodk
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 668 total points
ID: 40293597
You can do all those from SSMS , you can right click the database you want to script , choose all the objects and generate the script
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 664 total points
ID: 40293622
Unfortunately it's not quite that simple.  There are LOTS of options that control the scripting.  You need to go thru all those options and verify that everything you need will be scripted.

Honestly, if the data isn't large, it'd be easier and probably more accurate to restore the entire db, and then truncate/delete table data.

Author Comment

ID: 40293826
I am amazed that it is such a universal issue and no one has a generalized program to save the database structure in a file.  

I am also wondering if there is a way to execute the SSMS script which saves the database via program?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 40293881
Also, one more problem as I am using shared database it will not let me run SSMS scripts to save the file - so program is the only choice

Accepted Solution

Randy Knight, MCM earned 668 total points
ID: 40293977
There is commercial 3rd party software to do what you're looking for but nothing free that I'm aware of, other than the manual scripting out of the database using SSMS as mentioned above.

If you really want to do this from code, you need to take a look at SQL-SMO.  That is the object model that you can use from .NET to do all kinds of things within SQL Server.  In fact it's what SSMS uses.


Author Closing Comment

ID: 40435246
thank you

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question