Solved

Derived Attributes

Posted on 2004-09-27
5
2,865 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 500 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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