SQL Server Error Msg 273 – Cannot insert an explicit value into a GENERATED ALWAYS column in table ‘%.*ls’. Use INSERT

In this blog post, let’s learn about the error message “Cannot insert an explicit value into a GENERATED ALWAYS column in table ‘%.*ls’. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. – 16” in Microsoft SQL Server, the reason why it appears and the solution to fix it.

SQL Server Error Message

Cannot insert an explicit value into a GENERATED ALWAYS column in table ‘%.*ls’. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. – 16

Reason for the Error

SQL Server Error Message 273 occurs when you try to explicitly insert a value into a timestamp column in a table. A timestamp column is a special data type in SQL Server that is used to track changes to a row in a table.

Solution

The error message suggests two solutions:

  1. Use INSERT with a column list to exclude the timestamp column: You can specify the columns into which you want to insert values in the table. This way, you can exclude the timestamp column from the insert statement. In this case, the timestamp column will be automatically populated with a unique binary number for each row.
  2. Insert a DEFAULT into the timestamp column: If you want to explicitly insert a value into a timestamp column, you can use the DEFAULT keyword. This sets the timestamp column to its default value, which is the current date and time.

It’s important to note that the timestamp data type has been deprecated in SQL Server and is replaced by rowversion data type. Therefore, if you have the ability to update the table schema, it’s recommended to switch to rowversion instead.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this blog post, let’s learn about the error message “1459 – An error occurred while accessing the database mirroring...
In this blog post, let’s learn about the error message “7937 – Columnstore index has one or more missing column...