Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to backup the schema of a sql server 2005 database from the command line. Whats the best way to do this?


I ended up buying SQL Compare 8.1 from Red Gate Software.

It works just as well as Change Director and is 1500 dollars cheaper.

share|improve this question

The other responses about not having a command line tool are true, but there are third party applications to do this.

Disclaimer: I work for Quest Software, who sells Change Director for SQL Server. It does schema-only snapshots, plus notifies you if the schema changes. It can monitor tons of servers, and you can use it to sync schemas between multiple servers, like development and production.

share|improve this answer

Use the BACKUP DATABASE command to backup the entire database. This will backup the schema and the data. There isn't a single command to script out just the schema.

share|improve this answer

The schema specifically, and not the data? Why are you backing up just the schema? You should be preserving your source code, not trying to retrieve it from your database.

To specifically script schema objects, have a look at SMO or PowerShell. This SMO method (Schema.Script) might be useful.

For full backups (schema and data) you can issue a BACKUP DATABASE command via SQLCMD.

share|improve this answer

Found that my question was a duplicate to the same question on

The answer there was to right click on the database and select Tasks->Generate Scripts

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.