Reputation: 200
I created a schema script for an sql server database called test.
I want to execute this script in the same server where the test database is found, but for sure with different name, suppose test2.
when I opened the scripts, it starts by CREATE DATABASE [test] and the name test is used many times in the script. so how to safely change database name in the script without affecting the original database?
Note: changing name by just replacing it's name is not a solution because it's name is a part of many procedures and functions
Upvotes: 2
Views: 474
Reputation: 6739
No need to use database name in each and every query. Just use
USE [Database_Name]
in the above of the script file, then it will consider the database for the entire script until you specify another database name inside the script.
Eg:-
USE My_Database_1
Script_1
Script_2
.
.
Script_n
--Another Database if required
USE My_Database_2
Script_1
Script_2
.
.
Script_n
Upvotes: 3