If you’ve ever tried to insert values into an identity column in SQL Server, you might’ve seen an error like this:
Cannot insert explicit value for identity column in table ‘Artists’ when IDENTITY_INSERT is set to OFF.
This is normal. An identity column is there for a reason. It automatically populates the column with an incrementing value for each row that’s inserted. Therefore there’s no need for you to insert a value into that column.
However, sometimes you do need to insert a value into an identity column. For example, you could be populating the database with data that needs to retain its own identity values. If this is the case, you’ll need to override the IDENTITY
property. Here’s how.