Sunday, February 26, 2012

find computed columns in all tables

How do i find all the computed columns in all tables and also what the
computation is ? ThanksHassan
Have a look at COLUMNPROPERTY ( id , column , property ) in the BOL.
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:OaphViKRFHA.648@.TK2MSFTNGP14.phx.gbl...
> How do i find all the computed columns in all tables and also what the
> computation is ? Thanks
>|||Thats a start, but how do I find the formula for that computed column
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eLMc%23qKRFHA.3076@.TK2MSFTNGP14.phx.gbl...
> Hassan
> Have a look at COLUMNPROPERTY ( id , column , property ) in the BOL.
>
> "Hassan" <fatima_ja@.hotmail.com> wrote in message
> news:OaphViKRFHA.648@.TK2MSFTNGP14.phx.gbl...
>|||You find the source code in syscomments:
use tempdb
go
CREATE TABLE t(c1 int, c2 AS c1 * 23)
GO
SELECT text FROM syscomments
WHERE id = object_id('t')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Hassan" <fatima_ja@.hotmail.com> wrote in message news:%23iIHAuKRFHA.3560@.TK2MSFTNGP14.phx.
gbl...
> Thats a start, but how do I find the formula for that computed column
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:eLMc%23qKRFHA.3076@.TK2MSFTNGP14.phx.gbl...
>|||You can find the formula for a computed column in the syscomments table
(undocumented for this purpose). The undocumented procedure
sp_MShelpcolumns also provides this information, but you may find it
easier to use something like this:
SELECT o.name as TableName, c.name as ColumnName, cm.text as Formula
FROM syscolumns c INNER JOIN sysobjects o ON c.id=o.id
INNER JOIN syscomments cm ON cm.id = c.id and cm.number = c.colid
WHERE o.type='U'
Razvan|||SELECT OBJECT_NAME(col.id) AS TableName, col.name AS ColumnName, com.text AS
Formula
FROM syscolumns col
INNER JOIN syscomments com
ON col.id = com.id
AND col.colid = com.number
WHERE OBJECTPROPERTY(col.id, 'IsUserTable') = 1
Jacco Schalkwijk
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:%23iIHAuKRFHA.3560@.TK2MSFTNGP14.phx.gbl...
> Thats a start, but how do I find the formula for that computed column
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:eLMc%23qKRFHA.3076@.TK2MSFTNGP14.phx.gbl...
>

No comments:

Post a Comment