Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 544: Fix the Identity Column Error

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Error 544 means your INSERT statement supplied a value for an identity column while IDENTITY_INSERT is OFF for that table. SQL Server fills identity columns automatically, so it rejects any explicit value unless you first switch on IDENTITY_INSERT for that table in the same session. The fastest fix is to wrap the insert in SET IDENTITY_INSERT dbo.YourTable ON; and SET IDENTITY_INSERT dbo.YourTable OFF;, but the better fix depends on why you were supplying the value in the first place: if you simply listed the column by mistake, drop it from the column list; if you genuinely need to preserve specific IDs (restoring data, copying rows between databases, seeding reference data), turn IDENTITY_INSERT on and off carefully.

What You'll Need

  • Access to the database with permission to run INSERT statements and the ALTER permission on the table, which is required to use SET IDENTITY_INSERT.
  • A SQL client such as SQL Server Management Studio (SSMS) or Azure Data Studio, or any tool that lets you run T-SQL.
  • The name of the schema and table you are inserting into, for example dbo.Orders.
  • The name of the identity column in that table, in case you need to add it to an explicit column list.
  • The failing statement or the code that generated it, so you can see exactly which column carried the explicit value.

Step-by-Step

  1. Read the full error message. It names the table and the column: Cannot insert explicit value for identity column in table 'X' when IDENTITY_INSERT is set to OFF. Confirm you are looking at the identity column and not another column with a similar name. The insert will fail entirely; no partial row is written.
  2. Decide what you actually want. There are two outcomes. If the value you supplied is unnecessary, remove the column from the INSERT so SQL Server generates the next identity value for you. If the value must be preserved, you need IDENTITY_INSERT. Choose before editing, because the two routes lead to different statements.
  3. Route A: drop the column from the insert. Change INSERT INTO dbo.Products (ProductID, Name, Price) VALUES (101, 'Widget', 9.99) to INSERT INTO dbo.Products (Name, Price) VALUES ('Widget', 9.99). This is the right fix for new rows where the ID has no meaning to anything downstream. If the column list is omitted entirely, SQL Server expects a value for every non-nullable, non-identity column in table order, so always write an explicit column list; it is far safer and it prevents this error from recurring.
  4. Route B: turn on IDENTITY_INSERT. In the same query window and the same session as the insert, run:
    SET IDENTITY_INSERT dbo.Products ON;
    INSERT INTO dbo.Products (ProductID, Name, Price) VALUES (101, 'Widget', 9.99);
    SET IDENTITY_INSERT dbo.Products OFF;
    Run all three together. Only one table per session can have IDENTITY_INSERT ON at a time, and the setting resets when the session ends, but switching it off explicitly keeps the session usable for other work.
  5. Watch for the identity seed after a manual insert. Inserting an explicit value does not automatically move the identity counter forward. If you insert 101 into a table whose last generated value was 50, the next automatic insert still tries 51. Check the current value with DBCC CHECKIDENT ('dbo.Products', NORESEED); and reset it with DBCC CHECKIDENT ('dbo.Products', RESEED, 101); so the next generated value is 102. Skip the reseed step and you risk a duplicate key error later.
  6. Test with a rolled-back insert. Before running a bulk load, wrap a small version in a transaction: BEGIN TRAN; SET IDENTITY_INSERT dbo.Products ON; INSERT ... ; ROLLBACK; and confirm the statement executes and the values land where expected. This catches column-order mistakes and truncation problems without leaving stray rows behind.
  7. Apply the same fix at the source. If the error comes from an application, ORM mapping or ETL package, the culprit is usually the entity model marking the key column as insertable. Update the model mapping, generated SQL or staging table definition so the identity column is excluded, rather than patching every individual insert at runtime.
  8. Verify the rows afterwards. Run a SELECT on the affected range to confirm values are what you intended, and check that no duplicate identity values exist: SELECT ProductID, COUNT(*) FROM dbo.Products GROUP BY ProductID HAVING COUNT(*) > 1; returns nothing if all is well.

Common Mistakes

  • Turning IDENTITY_INSERT on in a different session. A query window, a stored procedure called from another connection, or an application connection is a separate session. IDENTITY_INSERT applies only to the session that ran it.
  • Turning it on for two tables at once. Only one table per session can have IDENTITY_INSERT ON. Attempting to set a second table gives its own error until the first is switched off.
  • Forgetting to switch it off. The session keeps accepting explicit values for that table, which can quietly bypass identity generation in later work in the same window.
  • Skipping the reseed. The most common secondary error: inserts succeed, then the next automatic insert collides with a manually inserted ID.
  • Omitting the schema. SET IDENTITY_INSERT MyTable ON may resolve to the wrong schema if your default schema is not dbo. Always write dbo.MyTable or the correct schema name.
  • Supplying an explicit value in a linked-server or OPENROWSET insert. These contexts behave differently and should be tested separately; do not assume the setting carries across.

Tips

  • Keep the ON/INSERT/OFF trio in a single batch or script with error handling, such as TRY...CATCH in a stored procedure, so a failure still turns the setting off.
  • Always write explicit column lists in INSERT statements. It makes the code readable, immune to column reordering and far less likely to trigger error 544.
  • When copying data between databases, script a matching seed reset at the end of the load so identity generation on the destination continues cleanly.
  • For reference tables such as status codes or categories where fixed IDs matter, consider whether identity is the right design at all; a natural key can be simpler.
  • Labels and menu wording in client tools vary slightly by version and edition, so follow the equivalent screen if yours looks different.

Troubleshooting

If that did not work: first check that the SET statement ran in the same session as the INSERT and that it returned success rather than an error about permissions. Next, confirm the permission on the table; a user without ALTER rights can read the error even when the syntax is correct. If you still get error 544, the failing insert is probably coming from a different piece of code than the one you edited, so trace it with SQL Server Profiler or Extended Events, or search the codebase for the table and column name. If you get a different error after fixing 544, such as a duplicate key violation, the identity seed is behind your manual values; reseed with DBCC CHECKIDENT and retry.

If a stored procedure fails midway, check that the OFF statement actually executed; a transaction rollback does not undo IDENTITY_INSERT, so an aborted run can leave it ON for the remainder of the session. Close the session to reset it.

Frequently Asked Questions

What does error 544 actually mean?

Your INSERT supplied a value for an identity column, but IDENTITY_INSERT was OFF for that table. SQL Server generates identity values itself and refuses to accept an explicit one unless you switch the setting on.

Do I need IDENTITY_INSERT to copy rows between tables?

Only if you must preserve the original ID values, for example when related tables reference them. If new IDs are acceptable, omit the identity column from the insert instead.

Does turning on IDENTITY_INSERT affect other users?

No. The setting applies to the current session only. Other sessions continue with normal identity generation.

Why do I get a duplicate key error after inserting explicit values?

The identity counter was not advanced by the manual insert. Reset it with DBCC CHECKIDENT using the RESEED option and the highest value present in the table.

Can I insert explicit values into an identity column permanently?

Not through a setting. IDENTITY_INSERT is per session and must be enabled each time. For tables where you always supply keys, an identity column is usually the wrong choice.

Does this error occur in Azure SQL Database too?

Yes. The behaviour and the IDENTITY_INSERT workaround are the same, though your account needs the appropriate permissions on the table.