我如何可以以编程方式检索ALTER视图脚本在SQL Server 2005中的视图 [英] How can I programmatically retrieve the alter view script for a view in SQL Server 2005

查看:135
本文介绍了我如何可以以编程方式检索ALTER视图脚本在SQL Server 2005中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们让我们的使用改变了我们跟踪我们的申请报告,而不是根据某些应用领域的元数据一定有什么意见。这些字段可以在运行时被创建。我有一个标准的方法,来改变视图时字段添加或删除。我现在需要做编程然而,这意味着我需要能够拉电流阿尔特视图脚本,让我修改,然后对数据库执行它。最后两个步骤是很容易的,但第一部分是给我一些麻烦。

设计决定搁置(因为它们超出了我的手在这个特殊的例子)。我想知道如何获取的SQL Server Management Studio中使用的视图 - >编辑命令阿尔特视图脚本。

我需要为这个命令完全一样的输出,因为我有意见钩在我的剧本,让我的编辑发生。

相关问题,但不完全是我找的。

<一个href="http://stackoverflow.com/questions/467482/how-do-i-programmatically-retrieve-sql-server-stored-procedure-source-that-is-ide">How我编程方式检索SQL Server存储过程源是相同的SQL Server Management Studio的GUI返回源?

<一个href="http://stackoverflow.com/questions/21547/in-mssql-how-do-i-generate-a-create-table-statement-for-a-given-table">In MSSQL,我怎么生成一个给定的表CREATE TABLE语句?

解决方案

SSMS使用SMO在幕后。该的编剧可以检索的定义任何SQL对象。

如果你想有一个T-SQL基础的方法,然后使用 sys.sql_modules < /一>,它包含在数据库中,包括次每一个非加密的物体的T-SQL定义

We allow our uses to alter certain views for reports and what not based on some application field meta data that we keep track of in our application. These fields can be created at run time. I have a standard process in place to alter the views when a field is added or removed. I now need to do this programmatically however, which means I need to be able to pull the current Alter view script, make my modifications, and then execute it against the database. The last two steps are easy enough, but the first part is giving me some trouble.

Design decisions aside (as they are out of my hands in this particular instance). I would like to know how to retrieve the Alter view script that Sql server management studio uses for the View->Edit command.

I require the exact same output as that command because I have comment hooks in my scripts that allow my edits to occur.

Related questions, but not quite what I am looking for.

How do I programmatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?

In MSSQL, how do I generate a CREATE TABLE statement for a given table?

解决方案

SSMS uses SMO under the covers. The Scripter can retrieve the definition of any SQL object.

If you want a T-SQL based approach, then use sys.sql_modules, it contains the T-SQL definition of every non-encrypted object in the database, including views.

这篇关于我如何可以以编程方式检索ALTER视图脚本在SQL Server 2005中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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