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 6548595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:59:21+00:00 2026-05-25T11:59:21+00:00

I have a table where each row needs a timestamp marking the time it

  • 0

I have a table where each row needs a timestamp marking the time it has been inserted. I don’t have a lot of database experience, but something tells me that this would best be handled automatically on the database side, for example through a stored procedure.

There is a timestamp datatype in MS SQL, but reading about it, it is treated as a series of numbers and not as a DateTime object in C#. So couldn’t it just be a NVARCHAR datatype if I have to do the conversion anyway?

So simply put, what is the easiest way to (automatically?) put a timestamp on a row when it is inserted into a table?

Edit: the table definition is very simple. It only has two columns at the moment and still lacking the timestamp column.

        SqlCommand command = con.CreateCommand();
        command.CommandText = "INSERT INTO Bio VALUES (" +
            "@ID, @Name)";

        command.Parameters.AddWithValue("ID",number);
        command.Parameters.AddWithValue("Name", name);

        try
        {
            SqlDataReader thisReader = command.ExecuteReader();
            thisReader.Close();
        }
        catch { // Do something };

Solution Okay, it works now. I first tried adding the new column through the Server Explorer window in Visual Studio 2008. Finding my database, right click and selecting “New Query”. Then typing something like

ALTER TABLE dbo.MyTable ADD CreatedDate datetime NOT NULL DEFAULT (GetUtcDate())

But I got the message that

The ALTER TABLE SQL construct is not supported
The query cannot be represented graphically in the Diagram and Criteria Pane.

So instead I added it graphically. First “Open table definition” and adding CreatedDate under Column Name and datetime under Data Type. Removing the Allow Nulls check. Then in the Column Properties I added

getutcdate()

under the General section in the row called “Default Value or Binding”. Whenever a new row is inserted, the database automatically gives it the current date and time as a timestamp.

  • 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-25T11:59:22+00:00Added an answer on May 25, 2026 at 11:59 am

    to have a CreatedDate column in a table create it like this:

    ALTER TABLE dbo.MyTable ADD CreatedDate datetime NOT NULL DEFAULT (GetUtcDate())
    

    Edit: if afterwards you want to have the value updated at every update of that record you can reassign GetUtcDate() to that column or to another one (I called it Createddate so should not be used in the update, but you can either add another one or rename it Modifieddate). I would definitely include the update of such column in the stored procedure which does the UPDATE, no need for triggers here.

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

Sidebar

Related Questions

I have a table where each row has 13 TD elements. I want to
I have a table column where each row has one of three states, and
I have a DB table in which each row has a randomly generated primary
I have a table style page with rows. Each row has a checkbox. I
My mysql database has a table with several hundred thousand rows. Each row has
I have a SQL table where in each row I store the country and
I have a table with multiple rows in each row is a select list
I have a data table filled with text in each table row. How do
Imagine you have a normal table view where each row is an item on
I have a table with multiple rows. Each row is a form. I want

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.