使用 SMO 编写 PARTIAL 数据内容的脚本(仅匹配 WHERE 子句的行) [英] Using SMO to script PARTIAL data content (only rows matching a WHERE clause)

查看:25
本文介绍了使用 SMO 编写 PARTIAL 数据内容的脚本(仅匹配 WHERE 子句的行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SMO 用 SQL Server 数据库的数据填充 SQL Compact 数据库.

I use SMO to fill a SQL Compact database with the data of a SQL server database.

这是我实际使用的代码:

Here is the code I actually use:

foreach(Table l_tblCurrent in l_dbDatabase.Tables)
{
  if(l_tblCurrent.IsSystemObject) continue;

  ScriptingOptions l_scOptions = new ScriptingOptions();

  l_scOptions.NoIdentities        = true;
  l_scOptions.NoCollation         = true;
  l_scOptions.NoCommandTerminator = true;
  l_scOptions.NoFileGroup         = true;
  l_scOptions.ScriptSchema        = true;
  l_scOptions.ScriptData          = true;

  foreach(string l_strCurrent in l_tblCurrent.EnumScript(l_scOptions))
  {
    l_sccDBFCommand.CommandText = l_strCurrent.Replace("[dbo].", "");
    l_sccDBFCommand.ExecuteNonQuery();
  }
}

它工作得很好,但对于几个表,我不想复制所有行.我希望能够仅选择与要复制的 WHERE 子句匹配的行.

It works perfectly, but for several tables, I don't want to copy all the rows. I want to be able to select only rows matching a WHERE clause to be copied.

有可能吗?

推荐答案

看起来 SMO 不支持 WHERE 子句或任何其他限制记录数的机制.我建议的解决方法是创建一个包含记录子集的新表,编写脚本,然后删除它.一切都可以以编程方式完成.

Doesn't look like SMO supports WHERE clause or any other mechanism to limit the number of records. My suggested workaround is to create a new table containing the subset of records, script it, then drop it. Everything can be done programmatically.

这篇关于使用 SMO 编写 PARTIAL 数据内容的脚本(仅匹配 WHERE 子句的行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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