从 SQL Server 2012 数据库获取 .sql 文件 [英] Get .sql file from SQL Server 2012 database

查看:29
本文介绍了从 SQL Server 2012 数据库获取 .sql 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从使用 SQL Server 2012 的现有数据库获取 .sql 文件.这可能是因为我在导出选项中看到的只是分隔文件.

I need to get .sql files from an existing database with SQL Server 2012. Is this possible because all I see in the export option is delimited files.

例如)我有 30 条记录的 table1.我需要一个类似于下面的文件.(我知道我的语法不正确,但你应该明白这一点.

Ex.) I have table1 with 30 records. I need a file that would be something like what is below. (I know my syntax is incorrect, but you should get the point).

CREATE TABLE table1 (
    INSERT INTO table1 values (
   .......)

推荐答案

如果您只想生成一个 .sql 脚本,您可以通过在对象资源管理器中右键单击数据库并选择任务 > 生成脚本来实现:

If you just want to generate a .sql script you can do this by right-clicking the database in Object Explorer and choosing Tasks > Generate Scripts:

然后你可以选择数据库和所有对象,也可以只选择你想要的表:

Then you can select database and all objects, or you can select just the table you want:

然后选择一个位置,并确保在继续之前进入高级:

Then select a location, and be sure to go into Advanced before continuing:

在高级下,至少,将脚本的数据类型更改为架构和数据"(如果您这样做而不是正确备份的原因是因为您需要在 SQL 之前将数据导入数据库Server 2012,您可能应该将目标服务器版本选项更改为您的目标版本):

Under advanced, at the very least, change types of data to script to "Schema and Data" (if the reason you are doing this rather than a proper backup is because you need to import the data into a database earlier than SQL Server 2012, you should probably change the target server version option to whatever version you're targeting):

如果您在 Management Studio 中没有该选项,则您可能仍在运行客户端工具的 RTM 版本.从 SP1 开始,全部功能终于免费提供.在此处下载最新版本 - SP2:

If you don't have that option in Management Studio, you are probably still running the RTM version of the client tools. Full functionality has finally been made free as of SP1. Download the most recent version - SP2 - here:

http://www.microsoft.com/en-us/download/details.aspx?id=43351

(您需要 SQLManagementStudio 文件之一.)

(You want one of the SQLManagementStudio files.)

这篇关于从 SQL Server 2012 数据库获取 .sql 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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