Cannot insert a non-null value into a timestamp column

  • By accident, I deleted two records.

    I tried to insert these two records from the backup table but got an error below. How to do it?

    Cannot insert a non-null value into a timestamp column

  • the name timestamp column is very misleading...it's synonym of ROWVERSION is more descriptive.

    change your insert to not include the timestamp column...a new value will be created for you automaticaly, just like an IDENTITY() column would.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • This snipet will show you what a timestamp looks like when allowing the system to generate on the insert.

    USE tempdb;

    go

    CREATE TABLE stamp_test(

    TestDate DATETIME NOT NULL,

    TestStamp TIMESTAMP

    );

    GO

    SET NOCOUNT ON;

    INSERT INTO stamp_test (TestDate) VALUES ('October 10, 2005');

    INSERT INTO stamp_test (TestDate) VALUES ('November 10, 2005 10:01:01');

    INSERT INTO stamp_test (TestDate) VALUES ('December 6, 2005 11:01:01');

    INSERT INTO stamp_test (TestDate) VALUES ('January 5, 2006');

    INSERT INTO stamp_test (TestDate) VALUES ('02/07/2006');

    INSERT INTO stamp_test (TestDate) VALUES ('03/08/2006 14:01:01');

    INSERT INTO stamp_test (TestDate) VALUES ('04/06/2006 15:01:01');

    INSERT INTO stamp_test (TestDate) VALUES ('20060504');

    INSERT INTO stamp_test (TestDate) VALUES ('20060606 17:01:01');

    INSERT INTO stamp_test (TestDate) VALUES ('20060706 19:01:01');

    SET NOCOUNT OFF;

    GO

    SELECT *

    FROM stamp_test;

    GO

    John Miner
    Crafty DBA
    www.craftydba.com

  • Did you solved your problem?

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply