创建用于创建数据库和表的 SQL 脚本 [英] Create SQL script that create database and tables

查看:39
本文介绍了创建用于创建数据库和表的 SQL 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SQL 数据库和表,我想将它们复制到另一个 SQL Server 中.我想创建一个 SQL 脚本,在单个脚本中创建数据库和表.

I have a SQL database and tables that I would like to replicate in another SQL Server. I would like to create a SQL script that creates the database and tables in a single script.

我可以使用 SQL Management Studio 为每种情况(数据库和表)创建创建"脚本,但我想知道将两个创建"脚本合并到单个脚本中是否就足够了.

I can create "Create" script using the SQL Management Studio for each case (Database and Tables), but I would like to know if combining the both "Create" scripts into single script would be enough.

谢谢.

推荐答案

在 SQL Server Management Studio 中,您可以右键单击要复制的数据库,然后选择脚本数据库为"以让该工具创建适当的 SQL 文件将该数据库复制到另一台服务器上.您可以对要创建的每个表重复此过程,然后将这些文件合并为一个 SQL 文件.不要忘记在创建数据库之后但在创建任何表之前添加 using 语句.

In SQL Server Management Studio you can right click on the database you want to replicate, and select "Script Database as" to have the tool create the appropriate SQL file to replicate that database on another server. You can repeat this process for each table you want to create, and then merge the files into a single SQL file. Don't forget to add a using statement after you create your Database but prior to any table creation.

在更新的 SQL Server 版本中,您可以在 SSMS 中的一个文件中获取此信息.

In more recent versions of SQL Server you can get this in one file in SSMS.

  1. 右键单击数据库.
  2. 任务
  3. 生成脚本

这将启动一个向导,您可以在其中编写整个数据库或部分数据库的脚本.似乎没有这样做的 T-SQL 方式.

This will launch a wizard where you can script the entire database or just portions. There does not appear to be a T-SQL way of doing this.

这篇关于创建用于创建数据库和表的 SQL 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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