如何使用SQL脚本重新生成具有原始名称的DB [英] How to regenerate a DB with original name using SQL script

查看:108
本文介绍了如何使用SQL脚本重新生成具有原始名称的DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个MS SQL Server为特定数据库生成了一个数据库模式脚本。我打算在另一个MS SQL Server上创建完全相同的副本。但是当我在目标系统的SSMS中运行脚本时,它使用所有表修改了master数据库,而不是创建一个具有原始名称的单独数据库。



什么是出错了?我是以错误的方式创建脚本还是以错误的方式重新生成数据库?



请帮助



我尝试过:



MS SQL Server 2014 - > SSMS - >档案 - >打开 - >档案 - >选择.sql脚本 - >打开 - >执行

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

推荐答案

我通过创建脚本将脚本USE DATABASE 选项的值设置为 True 来解决。它在生成的脚本中创建了 use [DBName] 语句。然后在目标系统上,在执行此脚本之前,我只创建了一个与原始数据库名称完全相同的新数据库,然后执行该脚本。
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.


这篇关于如何使用SQL脚本重新生成具有原始名称的DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆