Per Rønne skrev:
> Hvad skulle egentlig fordelen være ved et beregnet felt, i forhold til
> at bruge et view, være?
Man undgår et ekstra objekt - og der er mulighed for at indeksere de
beregnede værdier.
Jeg har dog ikke selv brugt det - jeg prøvede lidt en gang, og droppede
det da det gav problemer med backup-procedurerne. Men min sql-guru
(Robert Vieira, Professional SQL Server 2000 Programming) skriver dog
følgende:
"Im actually surprised that I haven't heard much debate about the use of
computed columns. Rules for normalization of data say that we should not
have a column in our table for information that can be derived from
other columns - that's exactly what a computed column is!
I'm glad the religious zealots of normalization haven't weighed into
this one much, as I like computed columns as something of a compromise.
By default, you aren't storing the data twice, and you don't have issues
with the derived values not agreeing with the base values because they
are calculated on the fly directly from the base values. However, you
still get the end result you wanted. Note that, if you index the
computed column, you are indeed actually storing the data (you have to
for the index). This, however, has its own benefits when it comes to
read performance.
This isn't the way to do everything related to derived data, but it sure
is an excellent helper for most situations."
> Og bliver de beregnede værdier for disse beregnede felter lagret i
> selve databasen?
Som det fremgår af citatet ovenfor, lagres værdierne ikke som standard,
men de lagres hvis man lægger et indeks på kolonnen.
--
Jens Gyldenkærne Clausen
Svar venligst under det du citerer, og citer kun det der er
nødvendigt for at forstå dit svar i sammenhængen. Se hvorfor og
hvordan på
http://usenet.dk/netikette/citatteknik.html