Solved

Derived Attributes

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

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now