SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Generate SQL Scripts from Database

By Absinthe, 2008/02/15

Total article views: 1193 | Views in the last 30 days: 129

Modify the script to have your server in sServer and your database in sDatabase. By default the output will be in a directory on the C:\<databasename> . This should also be changed but is left as an exercise for the reader.

 

I attempted to use DMO to exactly reproduce the output that I get from Microsoft SQL Server Enterprise manager when I choose a database and then "Generate SQL Scripts" and choose the following settings:

General:

Script All Objects

Formatting:

Generate the CREATE command for each object

Generate the DROP command for each object

Generate scripts for all dependent objects

Include extended properties

Options:

Script database

Script database users and database roles

Script SQL Server Logins (Windows and SQL Server logins)

Script object-level permissions

Script indexes

Script full-text indexes

Script PRIMARY keys, FOREIGN keys, defaults, and check constraints

Windows text (ANSI)

Create one file per object

 

However, I do not want it to be exactly like that, as some things I do not want to delete first, but rather check if they exist first then only add them if they do. Specifically: Defaults,Users, Roles, and Logins. It turns out that when I tried to do this, generating the scripts for views, would for some reason trigger making several other objects at the same time regardless of your settings. So it required being made differently all by itself. I am posting this code here, because basically I have yet to see it all in one place. So in the spirit of the season, and just because I am an all around nice guy. Here is the code in VBScript. It is ugly and not commented at all... but I think you can get the point...Replace the values in sServer and sDatabase with stuff that works for you.

By Absinthe, 2008/02/15

Total article views: 1193 | Views in the last 30 days: 129
Your response
 
 
Related tags

DMO    
SQL Server 2000    
 
Related content

The abbreviation DMO means what in SQL 2000?

By Steve Jones | Category: DMO
(not yet rated) | 2,200 reads

Using SQL-DMO, which of the following will allow...

By Andy Warren | Category: DMO
(not yet rated) | 1,711 reads

SQL-DMO can be used from which of the...

By Steve Jones | Category: DMO
(not yet rated) | 1,781 reads

You write a small VB6 utility app that...

By Andy Warren | Category: DMO
(not yet rated) | 1,660 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com