Monday 11 July 2022

Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.

  Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.

-------------------------------------------------------------------------

The error message states that an insert could not be performed.

Cause:

The timestamp data type is an 8-byte data type that exposes automatically generated, unique binary numbers within a database.  It is generally used as a mechanism for version-stamping table rows.

Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a timestamp column within the database. This counter, the database timestamp, tracks a relative time within a database and not an actual time that can be associated with a clock.

A table can only have one timestamp column.  Every time that a row with a timestamp column is modified or inserted, the incremented databasetimestamp value is inserted in the timestamp column.

 

Non Working Insert

 

INSERT INTO [TableName]
VALUES
(-999999999999,
-899999999999999,
‘Smith’,
‘John’,
null,
1/1/2012,
1/1/2012
)

Solution:

Perform insert using “DEFAULT” see example below.

INSERT INTO [TableName]
VALUES
(-999999999999,
-899999999999999,
‘Smith’,
‘John’,
null,
DEFAULT,
DEFAULT
)

The timestamp column of a row can be used to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the timestamp value is updated. If no change is made to the row, the timestamp value is the same as when it was previously read.

No comments:

Post a Comment