使用C#从SQL Server数据库备份和还原筛选的数据 [英] Backup and Restore Filtered Data from SQL Server database using C#

查看:92
本文介绍了使用C#从SQL Server数据库备份和还原筛选的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为我的应用程序实现备份和还原功能.在这里,我要备份过滤的数据(而不是整个数据库).

I wish to implement backup and restore feature for my application. Here I want to backup filtered data(not the whole database).

Select * from Sales where CompanyId=1对于数据库中的所有表,并将这些数据写入file.bak文件,稍后可以将其用于还原.

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.

我的问题是,有什么方法可以使用SMO来实现此功能?如果您对如何实现此建议还有其他建议,我很高兴听到它.

My Question here is Is there any way to implement this feature using SMO? If you have any other suggestion about how to implement this, I am very happy to hear it.

请帮助我的朋友们..

推荐答案

没有实现备份的本机方法,但是可以尝试一些笨拙的解决方法来获得此功能.

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.

如果每个表都包含CompanyId字段,则可以基于公司ID创建分区模式/功能,并将模式的每个分区专门放在单独的文件组上.然后,这会将每个CompanyId的数据拆分到一个不同的文件组中,这是关键,因为可以使用SQL而不是整个数据库来执行文件/文件组级别的备份.

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. 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.

除非最后一个选择,否则我不会这样做,我想我会确切地确定备份/还原要求是什么,并检查是否有更好的选择/选择.

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.

这篇关于使用C#从SQL Server数据库备份和还原筛选的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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