for identity column in table 'tablename' when IDENTITY_INSERT is set to OFF.
This error occurs when you try to insert a row into a table that has a column that auto-generates an ID. Although most times this is how you want the table to perform, at times you may need to explicity set the ID of the record you are entering.
In the same window as you are running your SQL statement, run the following (where [database.table] is the name of your database and table which you are trying to insert the record):
set IDENTITY_INSERT [database.table] ON
After you run your SQL query, remember to turn identity insert off again:
set IDENTITY_INSERT [database.table] OFF
Sample code in its entirety:
set IDENTITY_INSERT dbo.site_users ON
INSERT INTO site_users (user_id, username, password) values (24, 'test', 'password')
set IDENTITY_INSERT dbo.site_users OFF
| There are 10 users online |
| 626,670 total unique visitors |
| 1,211,301 total pageviews |
| 396 visitors in the last 24 hours |
| 250 total visitors today |
| 346 pageviews today |
| This page has been visited 10,362 times |
| Most users online at once: 52 on 12/13/2009 |
