MetaGuru
MetaGuru

Reputation: 43873

How do I create a new database from a saved schema script in SQL Server 2005?

I used the Database Publishing Wizard to generate a script of the schema for a database, how do I make a new database based on this .sql file?

Upvotes: 0

Views: 123

Answers (4)

Gishu
Gishu

Reputation: 136673

I've seen this used where I work - the osql command line utility for MS SQL. You can create databases and run DML queries too via string or file input

Upvotes: 0

Bob
Bob

Reputation: 99824

Open the SQL file, and add the CREATE DB syntax to the top.

http://msdn.microsoft.com/en-us/library/aa258257.aspx

Save it and run it with sqlcmd or query analyzer.

Or use Management Studio to create the empty db, and run the sql query against that.

From what I have seen with the sql server publishing wizard, it will not create the DB for you, just the tables and data.

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1064184

Typically, you would open a query analyzer window (right-click on the server; new query in Management Studio) and just run the script. It depends, though, on what the script contains - i.e. does it create the db - or just the tables. You may need to create the empty db yourself first.

Upvotes: 0

tpdi
tpdi

Reputation: 35171

Run the sql file against the database, from the command line client or some other client:

sqlcmd -d databasename < dumpscript.sql

Upvotes: 0

Related Questions