从一个数据库获取 SQL 以仅使用 SQL 创建类似的数据库
我想转储一个 SQL Server 数据库 - 获取创建类似数据库所需的所有 SQL 代码。我拥有 DatabaseA
的完整在线权限,我可以使用 SQL 为其提供数据并将结果返回到表中的行中。
我无法使用企业管理器、任何应用程序、实用程序等。我只能用纯 SQL 来喂它。
我追求的是SQL代码,比如CREATE TABLE
等等。这样我就可以将其粘贴到查询中,瞧 - 在 DatabaseB
中创建表、过程、函数。
我不会不会复制数据。
这部分实现了我想要的,它为我提供了过程和功能:
Select object_Name(object_ID),definition from sys.SQL_Modules
但不适用于表格。
I want to dump one SQL Server database - get all SQL code necessary to create a similar database. I have full online rights to DatabaseA
, I can feed it with SQL and get the results back in rows in a table.
I do not have the possibility to use Enterprise Manager, any applications, utilities or the like. I can only feed it with pure SQL.
What I am after is SQL code, like CREATE TABLE
and so on. So that I just can paste this into a query and voila - tables, procedures, functions are created in DatabaseB
.
I will not copy the data.
This partly does what I want, it gives me procedures and functions:
Select object_Name(object_ID),definition from sys.SQL_Modules
But not for tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用命令行,也可以创建存储过程来创建备份,然后使用该备份创建新数据库。我经常使用命令行。这是以前的 具有命令行示例和存储过程示例链接的堆栈问题。
You can use the command line or you can create a stored procedure to create a back up, then use that backup to create a new database. I have used the command line often. Here is a previous Stack question that has a command line example and a link to a stored procedure example.
您可以在 SQL Server Management Studio 中为整个数据库或特定数据库对象生成脚本。
为此,右键单击数据库,然后选择“任务”,然后选择“生成脚本”。
然后,它将打开一个向导,您可以选择为完整数据库或仅特定数据库对象编写脚本。
You can generate scripts in SQL Server Management Studio for an entire database or specific database objects.
To do this, right click the database then select Tasks then select Generate Scripts.
It will then open a wizard which will give you the option to choose to script the full database or just specific database objects.