0

SSMS 允许您右键单击表和“将表编写为”->“选择为”。我认为 SSMS 中的几乎所有内容都是通过 SMO 脚本引擎完成的,但我似乎找不到通过 SMO 执行此操作的方法,除非循环遍历列并自己生成脚本。

我的 Google-Fu 是不是很弱,还是人们只是不使用 SMO 来做这样的事情?我在任何地方都找不到任何示例脚本,但它似乎是一种常见的需求。

4

1 回答 1

2

看起来Script()表格的功能可以做到这一点:

Server server = new Server(".");
Database northwind = server.Databases["Northwind"];
Table categories = northwind.Tables["Categories"];
StringCollection script = categories.Script();
string[] scriptArray = new string[script.Count];
script.CopyTo(scriptArray, 0);

现在scriptArray将包含一个 SQL 命令列表,字符串数组的第一个条目将是set ansi_nulls on. 请参阅此博客文章

于 2010-05-28T14:41:24.177 回答