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

  • Home
  • SEARCH
  • 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 8906165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:34:52+00:00 2026-06-15T02:34:52+00:00

I need to create a column age in a SQL Server database. The values

  • 0

I need to create a column age in a SQL Server database.

The values of this column should be calculated based on the values of the column DOB.

Also its values should increment as Age increases.

  • 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-06-15T02:34:54+00:00Added an answer on June 15, 2026 at 2:34 am

    You should use a computed column to solve this problem. Something with a definition similar to this:

    ALTER TABLE Customers ADD Age AS datediff(year, DOB ,getdate())
    

    Original statement taken from and further information available at BlackWasp.

    Edit:

    MSDN explains computed columns as:

    A computed column is computed from an expression that can use other
    columns in the same table. The expression can be a noncomputed column
    name, constant, function, and any combination of these connected by
    one or more operators. The expression cannot be a subquery.

    Unless otherwise specified, computed columns are virtual columns that
    are not physically stored in the table. Their values are recalculated
    every time they are referenced in a query. The Database Engine uses
    the PERSISTED keyword in the CREATE TABLE and ALTER TABLE statements
    to physically store computed columns in the table. Their values are
    updated when any columns that are part of their calculation change. By
    marking a computed column as PERSISTED, you can create an index on a
    computed column that is deterministic but not precise. Additionally,
    if a computed column references a CLR function, the Database Engine
    cannot verify whether the function is truly deterministic. In this
    case, the computed column must be PERSISTED so that indexes can be
    created on it. For more information, see Creating Indexes on Computed
    Columns.

    Computed columns can be used in select lists, WHERE clauses, ORDER BY
    clauses, or any other locations in which regular expressions can be
    used, with the following exceptions:

    Computed columns used as CHECK, FOREIGN KEY, or NOT NULL constraints must be marked
    PERSISTED. A computed column can be used as a key column in an index or as part of any
    PRIMARY KEY or UNIQUE constraint if the computed column value is defined by a
    deterministic expression and the data type of the result is allowed in index
    columns.

    For example, if the table has integer columns a and b, the computed column a + b can be
    indexed, but computed column a + DATEPART(dd, GETDATE()) cannot be indexed because the
    value may change > in subsequent invocations.

    A computed column cannot be the target of an INSERT or UPDATE statement.

    The Database Engine automatically determines the nullability of
    computed columns based on the expressions used. The result of most
    expressions is considered nullable even if only nonnullable columns
    are present, because possible underflows or overflows will produce
    null results as well. Use the COLUMNPROPERTY function with the
    AllowsNull property to investigate the nullability of any computed
    column in a table. An expression that is nullable can be turned into a
    nonnullable one by specifying ISNULL(check_expression, constant),
    where the constant is a nonnull value substituted for any null result.

    Source: MSDN – Computed Columns

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

Sidebar

Related Questions

Consider Microsoft SQL Server 2008 I need to create a table which can be
I need to create a table with this structure: Column A Column B Column
I need to create a column chart from values that I have stored in
I have a column date and its format (Y-m-d -time). I need to create
I need to create a new column dinamically in SQL with a counter depending
I create a column as primary key , does this create indexes automatically ?
I need to create a 2 column array in ABAP so that a program
I have a project in C# where I create my tables in SQL server
I have been fiddling with this issue all day now. I need to create
I need to create an idbag in hibernate 3 where the collection-id column defaults

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.