从 SQL Server 2012 数据库获取 .sql 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15735722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get .sql file from SQL Server 2012 database
提问by Andrew
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.
我需要从 SQL Server 2012 的现有数据库中获取 .sql 文件。这可能是因为我在导出选项中看到的只是分隔文件。
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).
例如)我有 30 条记录的 table1。我需要一个类似于下面的文件。(我知道我的语法不正确,但您应该明白这一点)。
CREATE TABLE table1 (
INSERT INTO table1 values (
.......)
回答by Aaron Bertrand
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:
如果您只想生成一个 .sql 脚本,您可以通过在对象资源管理器中右键单击数据库并选择任务 > 生成脚本来执行此操作:
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:
然后选择一个位置,并确保在继续之前进入高级:
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):
在高级下,至少,将要脚本的数据类型更改为“架构和数据”(如果您这样做而不是正确备份的原因是因为您需要将数据导入 SQL Server 2012 之前的数据库中,您可能应该将目标服务器版本选项更改为您的目标版本):
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:
如果您在 Management Studio 中没有该选项,则您可能仍在运行客户端工具的 RTM 版本。从 SP1 开始,全部功能终于免费提供。下载最新版本 - SP2 - 在这里:
http://www.microsoft.com/en-us/download/details.aspx?id=43351
http://www.microsoft.com/en-us/download/details.aspx?id=43351
(You want one of the SQLManagementStudio
files.)
(您需要其中一个SQLManagementStudio
文件。)
回答by Hogan
Right click on the database under Tasks click generate scripts and wizard will open and then you can export the table structure and data to another database.
右键单击任务下的数据库单击生成脚本,向导将打开,然后您可以将表结构和数据导出到另一个数据库。
You have to select the tables and other schema you want to export and on one of the pages is a check box to select export table data.
您必须选择要导出的表和其他架构,其中一页上有一个复选框来选择导出表数据。
This will generate sql statements for your database.
这将为您的数据库生成 sql 语句。
This may not be available in the express version, I've not checked.
这在快速版本中可能不可用,我没有检查过。
回答by Hackerman
You have all these alternatives to start the SQL Server Import and Export Wizard
您有所有这些替代方法来启动 SQL Server 导入和导出向导
- On the Start menu, point to All Programs, point to Microsoft SQL Server, and then click Import and Export Data.
- In SQL Server Data Tools (SSDT), right-click the SSIS Packages folder, and then click SSIS Import and Export Wizard.
- In SQL Server Data Tools (SSDT), on the Project menu, click SSIS Import and Export Wizard.
- In SQL Server Management Studio, connect to the Database Engine server type, expand Databases, right-click a database, point to Tasks, and then click Import Data or Export data.
- In a command prompt window, run
DTSWizard.exe
, located inC:\Program Files\Microsoft SQL Server\100\DTS\Binn\
(or probably\110\
rather than\100\
in your case).
- 在开始菜单上,指向所有程序,指向 Microsoft SQL Server,然后单击导入和导出数据。
- 在 SQL Server Data Tools (SSDT) 中,右键单击 SSIS 包文件夹,然后单击 SSIS 导入和导出向导。
- 在 SQL Server Data Tools (SSDT) 的“项目”菜单上,单击“SSIS 导入和导出向导”。
- 在 SQL Server Management Studio 中,连接到数据库引擎服务器类型,展开数据库,右键单击数据库,指向任务,然后单击导入数据或导出数据。
- 在命令提示符窗口中,运行
DTSWizard.exe
,位于C:\Program Files\Microsoft SQL Server\100\DTS\Binn\
(或可能\110\
而不是\100\
您的情况)。
Saludos ;)
萨鲁多斯 ;)