简体   繁体   English

使用C#从SQL Server数据库备份和还原筛选的数据

[英]Backup and Restore Filtered Data from SQL Server database using C#

I wish to implement backup and restore feature for my application. 我希望为我的应用程序实现备份和还原功能。 Here I want to backup filtered data(not the whole database). 在这里,我要备份过滤的数据(而不是整个数据库)。

Like Select * from Sales where CompanyId=1 For all tables in database and write these data to a file.bak file, later which I can be used for restore purpose. Select * from Sales where CompanyId=1 Company ID Select * from Sales where CompanyId=1一样对于数据库中的所有表,并将这些数据写入file.bak文件,以后可以将其用于还原目的。

My Question here is Is there any way to implement this feature using SMO? 我的问题是,有什么办法可以使用SMO来实现此功能? If you have any other suggestion about how to implement this, I am very happy to hear it. 如果您对如何实现此建议还有其他建议,我很高兴听到它。

Please help me friends.. 请帮助我的朋友..

There is no native way in which you are going to achieve this backup, but there are some awkward workarounds you can do to try to get this functionality. 没有实现此备份的本机方法,但是您可以尝试一些尴尬的解决方法来尝试获得此功能。

If every table includes the CompanyId field, you could create a partition schema / function based on the company Id, and specifically place each partition of the schema on to a separate file group. 如果每个表都包含CompanyId字段,则可以基于公司ID创建分区模式/功能,并将模式的每个分区专门放在单独的文件组上。 This has then split the data for each CompanyId onto a different file group, which is the key since there is the functionality to perform a file / file group level backup in SQL instead of the entire database. 然后,这会将每个CompanyId的数据拆分到一个不同的文件组中,这是关键,因为可以使用SQL而不是整个数据库来执行文件/文件组级别的备份。

I wouldn't do this unless it was the last option, I think I would work out exactly what the backup / restore requirements are, and check whether there are better options / choices. 除非是最后一个选项,否则我不会这样做,我想我会确切地确定备份/还原要求是什么,并检查是否有更好的选项/选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM