[英]How to export 'Sql File' of a Table using C# code
基本上,如果要进行完整备份,包括表数据,存储的proc,视图等,则可以使用SQL脚本
BACKUP DATABASE School_Management TO DISK = 'D:\SQL Backup\SchoolManagement\SM_20180314.bak' WITH FORMAT,
MEDIANAME = 'SM_Backups',
NAME = 'Full Backup of School_Management';
您可以通过C#代码运行上述脚本,并将备份路径作为参数传递。 让我知道您是否需要更多细节
尽管不是适当的备份,但是简单的EXP实用程序(是, 原始导出,而不是Data Pump)可能做得很好。
为什么是原始 EXP? 因为您可以在计算机上运行它,所以它将导出整个用户(表,过程,程序包等)并在计算机上创建文件。 Data Pump是一种现代的导出实用程序,功能强大得多,但是-要使用它,您必须有权访问数据库服务器(即,其目录中存储了导出的文件。有关文档的所有内容,请阅读更多信息)。
因此,对它的外观进行了小幅演示-我将导出我的SCOTT用户:
c:\Temp>exp scott/tiger@xe file=scott.dmp
Export: Release 11.2.0.2.0 - Production on Sri O×u 14 20:13:30 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
Export done in EE8MSWIN1250 character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SCOTT
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SCOTT
About to export SCOTT's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SCOTT's tables via Conventional Path ...
. . exporting table DEPT 4 rows exported
. . exporting table EMP 12 rows exported
<snip>
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully with warnings.
c:\Temp>
c:\Temp>dir scott.dmp
Volume in drive C is OSDisk
Volume Serial Number is 7635-F892
Directory of c:\Temp
14.03.2018. 20:13 1.310.720 scott.dmp
1 File(s) 1.310.720 bytes
0 Dir(s) 346.085.478.400 bytes free
c:\Temp>
现在可以将生成的.DMP文件传输到其他数据库,导入(使用IMP命令),然后在几分钟之内启动并运行它(确定,这取决于新数据库上的环境是否友好)对于您导入的用户-例如,您通过数据库链接访问的不存在的用户等可能会破坏喜悦,但这是另外一回事了。
除此之外,请调查RMAN(恢复管理器)的用法:
Recovery Manager(RMAN)是一个Oracle数据库客户端,可以在数据库上执行备份和恢复任务,并自动管理备份策略。 它大大简化了备份,还原和恢复数据库文件。
这是备份数据库的正确方法; 但是,如果您只想“保存”一个用户的对象,则可能是一个过大的杀伤力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.