Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4086270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:42:09+00:00 2026-05-20T18:42:09+00:00

Table: Customer with columns Start_Time and End_Time. I need to add a new column

  • 0

Table: Customer with columns Start_Time and End_Time.

I need to add a new column “Duration” that is End_Time – Start_Time.
However, I need to do this using a trigger or procedure so that immediately after a new record is added to Customer table, the column Duration is updated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:42:10+00:00Added an answer on May 20, 2026 at 6:42 pm

    If you are using MS SQL, the ideal answer is probably a computed column.

    The less data you actually duplicate, the less opportunity for data inconsistency you will have, therefore the less consistency-ensuring/verification code and fewer maintenance processes will result from your schema.

    To set this up, (again, if using MS SQL), just add another column using the designer, and expand the “Computed Column Specification” area. (You can refer to other columns from this same table for this calculation.) Then enter “End_Time – Start_Time”. Depending on what you are going to do with this data, may want to use something like DATEDIFF(minute, Start_Time, End_Time) for your formula, instead. It’s exactly what this feature is for.

    If it is a very expensive calculation (which yours is probably not, from the information you’ve given) you could configure the results to be “persisted” – that’s very much like a trigger but clearer to implement and maintain.

    Alternately, you could create a new View that does the same calculation, and “project” this first table through it whenever getting information. But you probably already knew that, thus this answer was born! 🙂

    p.s. I personally recommend avoiding triggers like the plague. They cause extra operations that are often not expected by a developer, maintainer, or admin. This can cause operations to fail, return unexpected extra result sets, or modify rows that perhaps an admin was specifically trying to avoid modifying during an administrative (read: unsupported grin) fix.

    p.p.s. In this case I’d also recommend against a stored procedure, for the same maintenance reason as triggers. Although you could restrict security such that the only way to update the table was through a stored procedure, this can fail for many of the same reasons triggers can fail. Best to avoid duplicating the data if you can.

    p.p.p.s 🙂 This is not to say stored procedures are bad as a whole. On complex transactional operations or tightly integrated procedural filtering of large related tables in order to return a comparatively small result set they are still often the best choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with columns 'customer' and 'location' and I need to check
I am using Spring and JDBCTemplate. The scenario is a CUSTOMER table and ORDERS
This is the constraint I have on the Customers table. ALTER TABLE Customers ADD
Problem: Customer X has requested that pages using XML DataBinding and Databound tables in
I am creating a customer table with a parent table that is company. It
I have a database with this table: Customer - ID - Phone - Cell
I have a Customer table --> CustomerNumber and CustomerName columns I have a Sales
I have a table called customer which has, among others, a column called name
MYSQL Database: I have a table of data that I need to put into
Hi I have a table Customer. One of the columns in table is DateCreated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.