?
Solved

Default Constraint Question - SQL Server 2005

Posted on 2010-08-18
3
Medium Priority
?
226 Views
Last Modified: 2012-05-10
Hi,
I was looking at documentation from Microsoft about their AdventureWorks Database :
http://msdn.microsoft.com/en-us/library/ms124879(v=SQL.100).aspx

In their SalesOrderHeader table, they have a column "SubTotal" that they define  as :
     Sales subtotal:  Computed as SUM(SalesOrderDetail.LineTotal) for the SalesOrderID.

Q:  Can this be coded as a contraint or are they referring to the application computing this value?

Thanks much in advance,
hefterr
0
Comment
Question by:hefterr
[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
  • 2
3 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33470352
It is being computed by a trigger on the detail table, see trigger  SalesLT.[iduSalesOrderDetail]
0
 
LVL 1

Author Comment

by:hefterr
ID: 33470453
Hi cyberkiwi,
Thanks for the answer BUT could you please point me to this reference.  I am not familiar with using triggers.

Thanks,
hefterr
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 33470687
There is no reference.
Go directly to the database in SSMS and inspect it.

The SubTotal is defined as just a simple column, not a computed column.
Also, looking at table iduSalesOrderDetail and expanding to Triggers, you see the trigger there.  Right-click modify reveals the calculation used to update the header whenever something interesting happens to a detail record.
0

Featured Post

Independent Software Vendors: 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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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