When you create a new SQL Server database (including SQL Server 2000 Desktop Engine), the IDENTITY_INSERT options are set to OFF.
If you upsize a Microsoft Access table that contains a field of the AutoNumber data type, the field is created on SQL Server as an IDENTITY column. Unlike the AutoNumber data type, you cannot directly edit IDENTITY columns, nor explicitly insert data into an IDENTITY column while the IDENTITY_INSERT option for that table is set to OFF. To insert or update data in an IDENTITY column, you must set the IDENTITY_INSERT option to ON.
You can use the SET IDENTITY_INSERT statement to set the IDENTITY_INSERT option. SET IDENTITY_INSERT always references a table, and you should place it before the UPDATE or INSERT statement that modifies or inserts data into an IDENTITY column. The following example sets IDENTITY_INSERT for the NewEmployees table.
Save the query as qryAppend, and then close the query.
On the Tools menu, point to Database Utilities, and then click Upsizing Wizard.
Complete the steps in the Upsizing Wizard, and accept the default selections, except as noted below:
Create New Database: Yes
Which tables do you want to export to SQL Server: Export all tables
Add timestamp fields to tables: No, never
Create a new Access client/server application: Yes
After the Upsizing Wizard is finished, close the upsizing report.
Try to run the qryAppend stored procedure, and note the error message.
To set IDENTITY INSERT to ON, add the following line of SQL to the qryAppend stored procedure directly after the keyword AS:
SET IDENTITY_INSERT NewEmployees ON
When you are finished, your stored procedure should resemble the following text:
ALTER PROCEDURE qryAppend
AS
SET IDENTITY_INSERT NewEmployees ON
INSERT INTO
NewEmployees (EmployeeID, LastName, FirstName, Title,
TitleOfCourtesy, BirthDate, HireDate, Address, City, Region,
PostalCode, Country, HomePhone, Extension, Photo, Notes,
ReportsTo)
SELECT
Employees.EmployeeID, Employees.LastName, Employees.FirstName,
Employees.Title, Employees.TitleOfCourtesy, Employees.BirthDate,
Employees.HireDate, Employees.Address, Employees.City,
Employees.Region, Employees.PostalCode, Employees.Country,
Employees.HomePhone, Employees.Extension, Employees.Photo,
Employees.Notes, Employees.ReportsTo
FROM
Employees
Save the modified stored procedure, and then run it. Note that it succeeds.
For more information about IDENTITY INSERT, refer to SQL Server Books Online. To download the SQL Server Books Online, visit the following Microsoft Web site: