ACC2000: Can't Use Upsized Append and Make-Table Queries in an Access ProjectID: Q229681
|
When you try to run upsized make-table or append queries in a Microsoft Access project, you may receive the following error message:
Cannot run SELECT INTO in this database. The database owner must run sp_dboption to enable this option.
-or-
You may also encounter the first error message when running an upsized update query.Cannot insert explicit value for identity column in table 'table name' when IDENTITY_INSERT is set to OFF.
When you create a new Microsoft Data Engine (MSDE) or SQL Server database, the select into/bulkcopy and IDENTITY_INSERT options are set to OFF.
To set the select into/bulk copy option to ON for your database, create a stored procedure that uses the sp_dboption system stored procedure to toggle the setting. The following SQL sample modifies a database named MyDatabase so you can use SELECT INTO statements:
CREATE PROCEDURE SetMyOptions
AS
EXEC sp_dboption 'MyDatabase','bulkcopy','ON'
You can use the SET IDENTITY_INSERT statement to set the IDENTITY_INSERT option. SET IDENTITY_INSERT always references a table, and should be placed 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.
SET IDENTITY_INSERT NewEmployees ON
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
INTO
NewEmployees
FROM
Employees;
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;
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
CREATE PROCEDURE SetMyOptions
AS
EXEC sp_dboption 'NorthwindSQL','bulkcopy','ON'
SET IDENTITY_INSERT NewEmployees ON
When complete, 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
For more information about sp_dboption and IDENTITY INSERT, refer to SQL Server books online.
If you want to download the SQL Server Books Online, they are available at SQL Server 7.0 Books Online
Additional query words: prb
Keywords : kbdta AccessCS
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 13, 1999