将数据库模式导出到SQL文件中 [英] Export database schema into SQL file
问题描述
是否可以在 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:
- 右键单击要生成脚本的数据库
- 接下来,选择请求的表/表,视图,存储过程等(来自选择特定数据库对象)
- 点击高级 - 选择要编写脚本的数据类型
- 点击下一步并完成
- Right click the database you want to generate scripts for (not the table) and select tasks - generate scripts
- Next, select the requested table/tables, views, stored procedures, etc (from select specific database objects)
- Click advanced - select the types of data to script
- Click Next and finish
生成脚本时,有一个区域允许您输入脚本,约束,键等。从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屋!