将数据库模式导出到SQL文件中 [英] Export database schema into SQL file

查看:243
本文介绍了将数据库模式导出到SQL文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 MS SQL Server 2008 将数据库结构导出到 T-SQL 文件?

Is it possible in MS SQL Server 2008 to export database structure into a T-SQL file?

我不仅要导出表模式,还要导出主键,外键,约束,索引,存储过程,用户定义的类型/函数。

I want to export not only tables schema but also primary keys, foreign keys, constraints, indexes, stored procedures, user defined types/functions.

此外,我不希望数据出现在此 T-SQL 文件中。

Also I don't want the data to be present in this T-SQL file.

有什么方法可以实现吗?

Is there any way to achieve that?

推荐答案

通过SQL Server Management Studio为文件生成脚本,以下是步骤:

You can generate scripts to a file via SQL Server Management Studio, here are the steps:


  1. 右键单击要生成脚本的数据库

  2. 接下来,选择请求的表/表,视图,存储过程等(来自选择特定数据库对象)

  3. 点击高级 - 选择要编写脚本的数据类型

  4. 点击下一步并完成

  1. Right click the database you want to generate scripts for (not the table) and select tasks - generate scripts
  2. Next, select the requested table/tables, views, stored procedures, etc (from select specific database objects)
  3. Click advanced - select the types of data to script
  4. Click Next and finish

MSDN生成脚本

生成脚本时,有一个区域允许您输入脚本,约束,键等。从SQL Server 2008 R2开始,在脚本下有一个高级选项:

When generating the scripts, there is an area that will allow you to script, constraints, keys, etc. From SQL Server 2008 R2 there is an Advanced Option under scripting:

>

这篇关于将数据库模式导出到SQL文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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