检索计算字段的公式?

时间:2016-11-30 23:54:39

标签: sql-server calculated-columns

有没有办法在SQL Server中使用T-SQL读取计算列的公式?

我试过以下但是不起作用:

SELECT 
    COLUMN_NAME,
    COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'Formula')
FROM 
    INFORMATION_SCHEMA.COLUMNS 
WHERE 
    TABLE_NAME = 'Tablename'

1 个答案:

答案 0 :(得分:1)

CREATE TABLE FormulaTable(i INT ,j INT ,k AS i*j+10)


SELECT cc.definition 
FROM sys.computed_columns AS cc 
WHERE cc.name='k'

输出:

definition
-------------------------------------
([i]*[j]+(10))