Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I generated a database schema script for a particular database from one MS SQL Server. I intended to create the exact same copy on another MS SQL Server. But when i ran the script in SSMS of the target system, it modified the master database with all the tables instead of creating a separate database with original name.

What is going wrong? Am i creating the script the wrong way or regenerating the database the wrong way?

Kindly help

What I have tried:

MS SQL Server 2014 -> SSMS -> File -> Open -> File -> Choose .sql script -> Open -> Execute
Posted
Updated 4-Jan-18 23:56pm
v2
Comments
RedDk 4-Jan-18 18:30pm    
You'll have to edit the generated script to target an existing SCHEMA on the target system. And this, only assuming, that any "generation" also included CREATEs for all the tables and stoprocs/etc where the genesis is to take place.

Master will serve to contain the generation (by default). Under schema ".dbo".

But that might not be where you want it.
marjaan 4-Jan-18 23:50pm    
I think I should not need to edit the script, I am just not setting the proper options in Advanced options before generating the script. Just can't figure out which option has excluded the creation and then usage of that database, so that the generated script had to create all tables in master. Any thoughts on that?
Karthik_Mahalingam 4-Jan-18 23:08pm    
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
marjaan 4-Jan-18 23:49pm    
Oh ok. Why deleted comments are still shown to me? It's a bit confusing.
Maciej Los 5-Jan-18 1:54am    
It's because, you may want to restore them.

1 solution

I got around by creating the script setting the Script USE DATABASE option's value to True. It created the use [DBName] statement in the generated script. Then on target system, before executing this script, I simply created a new database with exact same name as the original one and then executed the script.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900