SQL Server error 1077 occurs when you try to insert an explicit value into an identity column without first enabling the ability to do so. The fix is to run SET IDENTITY_INSERT before the insert, perform the insert (listing the identity column and its value), then run SET IDENTITY_INSERT . Only one table in a session can have this setting ON at a time, and you need ALTER permission on the table.
This guide walks through the exact steps, the common pitfalls, and what to do when the error persists or you hit related issues.
What You'll Need
- Access to SQL Server Management Studio (SSMS), Azure Data Studio, or another client that can run T-SQL.
- Permissions to run
SET IDENTITY_INSERTon the target table (typically ALTER permission on the table). - The name of the table and the identity column, plus the value you want to insert.
- A backup or a test environment if you are modifying production data.
Step-by-Step
- Confirm the column is an identity column. In Object Explorer, expand the table, then Columns. The identity column is marked with a small key icon or shown as
IDENTITYin the properties. Alternatively, run:SELECT COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID('YourTable'), COLUMN_NAME, 'IsIdentity') AS IsIdentity FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'YourTable';
A result of 1 means it is an identity column. - Open a new query window connected to the correct database. Using the wrong database is a common cause of “table not found” errors.
- Enable identity insert for the table:
SET IDENTITY_INSERT dbo.YourTable ON;
Replacedbo.YourTablewith your schema and table name. This setting applies only to the current session and connection. - Write your INSERT statement and explicitly list the identity column along with all other columns you are providing values for. For example:
INSERT INTO dbo.YourTable (Id, Name, CreatedDate) VALUES (100, 'Sample', GETDATE());
You must include the identity column in the column list; otherwise SQL Server still generates a value and may ignore your supplied value or raise a different error. - Turn identity insert off immediately after the insert:
SET IDENTITY_INSERT dbo.YourTable OFF;
Leaving it on can cause confusion for later inserts in the same session and prevents other tables from using the setting. - Verify the inserted row with a SELECT statement. Check that the identity value matches what you intended and that no other rows were affected.
- If you need to insert into multiple tables, repeat steps 3–5 for each table. Remember: only one table per session can have IDENTITY_INSERT ON at any moment.
Common Mistakes
- Forgetting to include the identity column in the column list. Even with IDENTITY_INSERT ON, if you omit the identity column from the INSERT column list, SQL Server will attempt to generate a value and may raise an error or insert an unexpected value.
- Leaving IDENTITY_INSERT ON. This can cause subsequent inserts in the same session to fail or behave unexpectedly, and it blocks other tables from using the setting.
- Using the wrong table name or schema. The setting is per table, so a typo or missing schema prefix will enable it for the wrong object or fail silently.
- Assuming the setting persists across connections. IDENTITY_INSERT is session-scoped; a new query window or connection starts with it OFF.
- Not having sufficient permissions. You need ALTER permission on the table; without it, the SET statement fails with a permission error.
- Using IDENTITY_INSERT on a table that does not have an identity column. This raises an error because the setting only applies to tables with an identity property.
Tips
- Always wrap the ON/OFF pair in a TRY…CATCH block or use a transaction so that if the insert fails, you can ensure IDENTITY_INSERT is turned off.
- Use
DBCC CHECKIDENTto reseed the identity value after inserting explicit values, so future automatic inserts do not collide. For example:DBCC CHECKIDENT ('dbo.YourTable', RESEED, 100);sets the next value to 101. - Script the entire operation (SET ON, INSERT, SET OFF) so it can be reviewed and rerun safely.
- Test on a development copy before running on production, especially when reseeding identity values.
- If you frequently need to insert explicit identity values, consider whether the column truly needs to be an identity column, or whether a different key strategy would be better.
Troubleshooting
If you still get error 1077 after running SET IDENTITY_INSERT ON, check these points:
- Did the SET statement actually run in the same session and database context? Execute
SELECT SESSIONPROPERTY('IDENTITY_INSERT');to see if it is ON for the current session. Note that this returns the setting for the current session only. - Is another table already using IDENTITY_INSERT in the same session? Only one table per session can have it ON. Turn it off for the other table first.
- Are you using the correct table name? Include the schema, e.g.,
dbo.YourTable, and ensure the table exists in the current database. - Do you have ALTER permission? If not, ask a database administrator to grant it or run the statement under an account that has it.
- Is the column actually an identity column? Verify with the query in step 1. If it is not, you do not need IDENTITY_INSERT; the error may be misleading.
- Are you using a tool that resets the session? Some tools open a new connection for each statement. Run the SET and INSERT in a single batch or script.
- If the error occurs within a stored procedure or trigger, ensure the SET statement is executed in the same scope and that no other SET IDENTITY_INSERT is active.
If you continue to have problems, check the SQL Server error log for additional messages and verify that the database is not in a read-only state or subject to other restrictions.
Frequently Asked Questions
Can I insert into an identity column without SET IDENTITY_INSERT?
No. SQL Server automatically generates values for identity columns and rejects explicit values unless IDENTITY_INSERT is ON for that table in the current session.
Does SET IDENTITY_INSERT affect other users?
No. The setting is scoped to your session only. Other sessions are unaffected, but they cannot enable IDENTITY_INSERT for the same table simultaneously if you already have it ON in your session? Actually, the restriction is per session: each session can have only one table with IDENTITY_INSERT ON. Other sessions can enable it for the same table independently, but concurrent explicit inserts may cause conflicts.
What permissions do I need to use SET IDENTITY_INSERT?
You need ALTER permission on the table. Membership in the db_owner or sysadmin roles also works.
Why do I get error 1077 even after running SET IDENTITY_INSERT ON?
Common reasons: the SET statement ran in a different session or database, another table already has IDENTITY_INSERT ON in the same session, the table name is incorrect, or you lack permissions.
Can I use IDENTITY_INSERT with a temporary table?
Yes, if the temporary table has an identity column. Use the same syntax with the temp table name (e.g., #TempTable).
How do I reseed the identity value after inserting explicit values?
Use DBCC CHECKIDENT ('table_name', RESEED, new_reseed_value); to set the next value. For example, if you inserted up to 100, reseed to 100 so the next automatic value is 101.