Wednesday, March 7, 2012

Question on Formula

I have a computed field that I want to change the
formula. How do I do this in SQL ?
thanks in advance
You have to drop and recreate the computed column to change the formula:
CREATE TABLE a (b INT, c AS b*b)
GO
ALTER TABLE a DROP COLUMN c
GO
ALTER TABLE a ADD c AS b*2
Jacco Schalkwijk
SQL Server MVP
"Deck" <d@.d.com> wrote in message
news:uxX%23d5AYFHA.4000@.TK2MSFTNGP10.phx.gbl...
>I have a computed field that I want to change the
> formula. How do I do this in SQL ?
> thanks in advance
>
|||"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid > wrote
in message news:O1caxQEYFHA.3280@.TK2MSFTNGP09.phx.gbl...
> You have to drop and recreate the computed column to change the formula:
> CREATE TABLE a (b INT, c AS b*b)
> GO
> ALTER TABLE a DROP COLUMN c
> GO
> ALTER TABLE a ADD c AS b*2
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Deck" <d@.d.com> wrote in message
> news:uxX%23d5AYFHA.4000@.TK2MSFTNGP10.phx.gbl...
>
thanks, i was also thinking of the same way. but dropping and re-creating
the field will place the field on the last position. is there anyway to
maintain
its position to where it was?
|||hi,
Deck wrote:
> thanks, i was also thinking of the same way. but dropping and
> re-creating the field will place the field on the last position. is
> there anyway to maintain
> its position to where it was?
in a relational database the column position is insignificant... and should
be the same for client applications as you should not use SELECT * but a
well defined select list... anyway, you can achieve the desired result
creating a temporary table with all the columns in the desired order,
migrate data to the new table, drop the old one and renaming the new one...
and of course re-setting all idxs, fks, triggers, constraints, extended
properties...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.12.0 - DbaMgr ver 0.58.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

No comments:

Post a Comment