簡體   English   中英

如何使用C#代碼導出表的'Sql文件'

[英]How to export 'Sql File' of a Table using C# code

我已經開發了一個學校管理系統,該系統連接到數據庫。 現在,我要備份表。

我的想法是為每個表生成一個SQL文件,以后將用於備份。 我在Oracle SQL Developer中手動實現了此目標(如屏幕快照所示),首先導出SQL文件,然后導入這些文件。 現在,我想使用C#以編程方式進行此操作。 我在Google上進行了很多搜索,但沒有發現任何有用的信息。

oracle sql開發人員的屏幕截圖

基本上,如果要進行完整備份,包括表數據,存儲的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM