Sunday, March 25, 2012

Computed Columns

I have a quick question for someone that has worked with
computed columns. Can a computed column within a table
reference a field from another table in it's formula. If
so, how? Also, if using a view that joins multiple
tables, how can you do an insert with that view, or can
you? Have tried to look this up, but can't find much.
Thanks,
Van JonesHi Van,
1) You acces other tables on SQL Server 2000 if you use a user defined
function in the formula of your computed column.
2) You can insert in a view that joins multiple table if you create an
INSTEAD OF trigger on that view. Once again this is SQL Server 2000 only,
this won't work on earlier versions.
--
Jacco Schalkwijk
SQL Server MVP
"Van Jones" <anonymous@.discussions.microsoft.com> wrote in message
news:09b601c3a7a3$c4dcfa30$a401280a@.phx.gbl...
> I have a quick question for someone that has worked with
> computed columns. Can a computed column within a table
> reference a field from another table in it's formula. If
> so, how? Also, if using a view that joins multiple
> tables, how can you do an insert with that view, or can
> you? Have tried to look this up, but can't find much.
> Thanks,
> Van Jones|||Thanks for your help.
Van
>--Original Message--
>Hi Van,
>1) You acces other tables on SQL Server 2000 if you use a
user defined
>function in the formula of your computed column.
>2) You can insert in a view that joins multiple table if
you create an
>INSTEAD OF trigger on that view. Once again this is SQL
Server 2000 only,
>this won't work on earlier versions.
>--
>Jacco Schalkwijk
>SQL Server MVP
>
>"Van Jones" <anonymous@.discussions.microsoft.com> wrote
in message
>news:09b601c3a7a3$c4dcfa30$a401280a@.phx.gbl...
>> I have a quick question for someone that has worked with
>> computed columns. Can a computed column within a table
>> reference a field from another table in it's formula.
If
>> so, how? Also, if using a view that joins multiple
>> tables, how can you do an insert with that view, or can
>> you? Have tried to look this up, but can't find much.
>> Thanks,
>> Van Jones
>
>.
>|||Van,
Although there are ways to achieve what you ask, you should wonder
whether to use this. There is nothing you can do with a computed column
that you can't do with a view. However, creating a computed column
complicates the table structure, especially if it is based on a UDF.
I would avoid using the (SQL-Server proprietary) computed columns, and
use them only if I *really* needed them.
My 5 cents,
Gert-Jan
Van Jones wrote:
> I have a quick question for someone that has worked with
> computed columns. Can a computed column within a table
> reference a field from another table in it's formula. If
> so, how? Also, if using a view that joins multiple
> tables, how can you do an insert with that view, or can
> you? Have tried to look this up, but can't find much.
> Thanks,
> Van Jones

No comments:

Post a Comment