SQL Server:可从数据库检索的计算列定义? [英] SQL Server: Computed Column defintions retrievable from Database?
本文介绍了SQL Server:可从数据库检索的计算列定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中查询计算列的定义,但是找不到似乎要做我想要的命令...
例如,如果列定义为:
CallDT AS(CONVERT([datetime],dateadd(second,[StartDate] ,'01 / 01/1970'),(0)))
喜欢在数据库上运行命令以检索AS语句,因此我可以将其与其预期值进行比较。 (我正在开发一个SQL解析器,将现有数据库与DDL定义进行比较)...
这是可能吗?
创建表dbo。 Foo
(
StartDate int,
CallDT AS(CONVERT([datetime],dateadd(second,[StartDate],'01/01/1970'),(0)))
)
选择定义
来自sys.computed_columns
其中name ='CallDT'和object_id = object_id('dbo.Foo')
I would like to query the definition of a computed column from the database, but can't find a command that seems to do what I want...
For instance, if a column is defined as:
CallDT AS (CONVERT([datetime],dateadd(second,[StartDate],'01/01/1970'),(0)))
in the DDL, I would like to run a command on the database to retrieve that "AS" statement so I can compare it to its expected value. (I'm developing a SQL parser that will compare an existing database to a DDL definition)...
Is this possible?
解决方案
This works in SQL Server 2008
create table dbo.Foo
(
StartDate int,
CallDT AS (CONVERT([datetime],dateadd(second,[StartDate],'01/01/1970'),(0)))
)
select definition
from sys.computed_columns
where name='CallDT' and object_id=object_id('dbo.Foo')
这篇关于SQL Server:可从数据库检索的计算列定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文