?
Solved

Derived Attributes

Posted on 2004-09-27
5
Medium Priority
?
2,879 Views
Last Modified: 2013-11-19
How do derived attributes work?  I would like to see a typical SQL example, if possible.
0
Comment
Question by:lcor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 17

Expert Comment

by:BillAn1
ID: 12161355
homework????
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12161833
I'm guessing from your prior questions that you're a professional, so here's an typical example if a table already has numeric columns named TotalSales and TotalCosts:

ALTER TABLE TableA ADD GrossProfit as TotalSales - TotalCosts

[If I'm wrong, and you are asking for homework, then my answer is: I used to have a Chevy Attribute that I would derive to work, and it worked by pushing the gas peddle.  :) ]
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 2000 total points
ID: 12162160
Oh, as to how they work, you just define a column with a forumla or expression. You can use any column and most of the functions available in the flavor of SQL used by your brand of database.

When a new record is INSERTED, you don't specify the derived column, or try to insert a value into it, and the database will do that automatically.

It hurts the performance slightly for inserts and updates, but can dramatically improve performance on SELECT's, if you're SELECT'ing whatever the derived value is, because the SELECT will only have to fetch it, not calcuate it on the fly for every row you're querying.
0
 

Author Comment

by:lcor
ID: 12163960
Gee, guys, I hope I didn't offend anyone with my question.  I was just trying to be specific about what I was looking for.

Anyway, would the ALTER SQL command be included in script that creates the schema?
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12170439
Sorry, didn't notice the follow up question until now.

You can add an ALTER TABLE command to a longer script, or, if you're creating the table, you can define the derived column in the CREATE TABLE command:

CREATE TABLE TableA(Col1 int, Col2 int, Col3 as Col1 + Col2)

[I don't think anyone was offended. And I was happy to get to use my "derive to work" joke. :) ]
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question