March 12, 2018 at 5:44 am
Hi,
what is faster?
Best,
Jacek
March 12, 2018 at 6:13 am
jaryszek - Monday, March 12, 2018 5:44 AMHi,what is faster?
Best,
Jacek
It takes longer and is more intrusive to create a calculated column in a table than it is to create the calculation in a query. Is that what you mean?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
March 12, 2018 at 6:34 am
Yes,
exactly.
thank you!
Jacek
March 12, 2018 at 6:55 am
jaryszek - Monday, March 12, 2018 5:44 AMHi,what is faster?
Best,
Jacek
It depends on many factors, the data, type of calculation etc. What exactly are you trying to do?
😎
March 12, 2018 at 6:57 am
I am trying to do data standarization from Excel.
In Excel i have multiple columns where i am summing fields.
Best,
Jacek
March 12, 2018 at 10:20 am
How often is the data modified (INSERT, UPDATE, DELETE) compared to how often is the data queried?
March 12, 2018 at 10:38 am
jaryszek - Monday, March 12, 2018 6:57 AMI am trying to do data standarization from Excel.
In Excel i have multiple columns where i am summing fields.
Best,
Jacek
Can you elaborate a bit further please?
😎
You need to spell out the problem as you were explaining it to a child since we cannot see your data nor do we know the business requirements.
March 13, 2018 at 1:38 am
jaryszek - Monday, March 12, 2018 5:44 AMHi,what is faster?
Best,
Jacek
It depends on the data and query cost. Normally if you alter a table for a calculative field and select the same field , It'll be somewhat faster. But If you create a CTE within your SQL query for a calculative field , then the optimizer need to calculate and spend some time there (within SQL query) and execute it.
You can take the call based on the above information. Hope it helps !
March 13, 2018 at 2:58 am
Hi Guys,
thank you for help and support!
Data is only needed to pull out to Excel as data source for calculations.
There will be not a lot of query, more inserting and updating data.
Best,
Jacek
March 13, 2018 at 4:31 am
Hi Guys,
my relationships look like below:
And now within ServerDetailedInfoTable i should have several calculations fields. Like changing bytes for GB,
if conditionals and so on.
I am wondering the better way to do it is add calculated fields within view and view pull out to Excel or within this tables i should add calculated columns...
There will be inserting and updating mainly or deleting.
Best,
Jacek
March 13, 2018 at 8:38 am
jaryszek - Tuesday, March 13, 2018 2:58 AMHi Guys,thank you for help and support!
Data is only needed to pull out to Excel as data source for calculations.There will be not a lot of query, more inserting and updating data.
Best,
Jacek
Given that you expect more inserting and updating data than querying, it's probably better to do the calculations at query time, so in a query, view, or maybe even in the Excel spreadsheet if that is the primary consumer of this data. If the calculation is done within Excel to change bytes to GB for example, then it would be done on the user's computer instead of in the database server.
If this was a datamart, data warehouse, or some other reporting database then it would make more sense to do the calculation at the time of data insert or update.
March 13, 2018 at 11:11 am
One thing I would add ... It seems that for now the data is only being supplied to an Excel workbook , to which then calculations are done. In the future if other users or another department will need to do the same then better to centralise the calculations at the server so that two entities do not have different logic to try to arrive at the same number. And the information can be fed to other reporting tools as well. It also keeps the knowledge at the server on how to do the calculation rather than in one person's head / Excel sheet. Just a suggestion, just that if this is going to be a repeated process and numbers are critical then this may be the way to go.
----------------------------------------------------
March 13, 2018 at 12:35 pm
Without doing a deep read on the other responses, if a calculation is deterministic, then adding a PERSISTED computed column on a table will cause the answer to be calculated during the insert and persisted through the life of the row, which means if the affecting values in the row don't change, the calculated column won't either. That can make things extremely fast if you're already reading from the table anyway. The column can also be indexed, which means it can also be a part of a "covering index", which can make things a whole lot faster on top of it all.
Think of it as a single "materialized column" much like you'd find in an "Indexed View" ("materialized view" for some).
There are caveats to just about everything but, done correctly, PERSISTED computed columns can be a big help to read performance.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 13, 2018 at 8:43 pm
Jeff Moden - Tuesday, March 13, 2018 12:35 PMWithout doing a deep read on the other responses, if a calculation is deterministic, then adding a PERSISTED computed column on a table will cause the answer to be calculated during the insert and persisted through the life of the row, which means if the affecting values in the row don't change, the calculated column won't either. That can make things extremely fast if you're already reading from the table anyway. The column can also be indexed, which means it can also be a part of a "covering index", which can make things a whole lot faster on top of it all.Think of it as a single "materialized column" much like you'd find in an "Indexed View" ("materialized view" for some).
There are caveats to just about everything but, done correctly, PERSISTED computed columns can be a big help to read performance.
I also find they help a lot when the base table does not have a column in the right format , such as dates stored as strings.
----------------------------------------------------
March 13, 2018 at 9:48 pm
MMartin1 - Tuesday, March 13, 2018 8:43 PMJeff Moden - Tuesday, March 13, 2018 12:35 PMWithout doing a deep read on the other responses, if a calculation is deterministic, then adding a PERSISTED computed column on a table will cause the answer to be calculated during the insert and persisted through the life of the row, which means if the affecting values in the row don't change, the calculated column won't either. That can make things extremely fast if you're already reading from the table anyway. The column can also be indexed, which means it can also be a part of a "covering index", which can make things a whole lot faster on top of it all.Think of it as a single "materialized column" much like you'd find in an "Indexed View" ("materialized view" for some).
There are caveats to just about everything but, done correctly, PERSISTED computed columns can be a big help to read performance.
I also find they help a lot when the base table does not have a column in the right format , such as dates stored as strings.
Agreed. They have tons of uses. Combining DATE and TIME columns. Returning a date with no time. Pre-Concatenated names. Normalized searchable/joinable addresses. Pre-lookups. Luhn 10 and other checksums. Tons of other uses.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply