Resolving the "Record is deleted" Error Message when Appending Access Query Results to SQL Server

Appending Data to SQL Server from Access Query Results in Error

As a developer working with database applications, it’s not uncommon to encounter issues when appending data from an Access query into an existing table in SQL Server. In this article, we’ll delve into the world of database operations and explore the reasons behind the “Record is deleted” error message, which can be frustrating and challenging to resolve.

Understanding the Problem

The problem arises when attempting to insert data from an Access query into a SQL Server table using an append query or a DoCmd.RunSQL statement. The error occurs because of NULL values in the query results, which cause SQL Server to throw a “Record is deleted” error message without providing any error number.

Let’s break down the problem step by step:

  • We have two tables: tmakContact and qryContact. The latter is an Access query that retrieves data from multiple tables.
  • We’re using an append query or DoCmd.RunSQL statement to insert data into tmakContact.
  • The issue arises when NULL values are present in the Relationship and PhoneNumType columns of the qryContact query results.

Debugging Techniques

To resolve this issue, we’ll employ several debugging techniques:

Technique 1: Inspecting Table Structure

First, let’s verify that the tmakContact table doesn’t have any bit columns or other data type issues. We can check the table structure using SQL Server Management Studio (SSMS) or by running a simple query.

SELECT *
FROM tmakContact;

This will help us identify if there are any problematic data types or null values in the table.

Technique 2: Verifying Autonumber Primary Key

Next, we’ll check if the tmakContact table has an autonumber primary key column. If not, we can create one using SQL Server Management Studio (SSMS) or by running a script.

CREATE TABLE tmakContact (
    -- existing columns...
    ContactId INT IDENTITY(1,1) PRIMARY KEY,
    -- existing columns...
);

This will help us ensure that the table has a consistent primary key column.

Technique 3: Checking Default Values

We’ll also verify that any single/double columns in the tmakContact table have default values set to zero. This can be done using SQL Server Management Studio (SSMS) or by running a script.

ALTER TABLE tmakContact
ADD COLUMN Relationship BIT DEFAULT 0;

ALTER TABLE tmakContact
ADD COLUMN PhoneNumType BIT DEFAULT 0;

This will ensure that all single/double columns have default values set to zero, which can help prevent NULL value issues.

Technique 4: Adding a Row Version Column

Finally, we’ll add a row version column (also known as a timestamp) to the tmakContact table. This will enable SQL Server’s row version system, which allows for more efficient and reliable updates.

ALTER TABLE tmakContact
ADD COLUMN RowVersion TIMESTAMP DEFAULT GETDATE();

This will help resolve the NULL value issue caused by the “Record is deleted” error message.

Conclusion

By applying these debugging techniques and making the necessary adjustments to your table structure, primary key configuration, default values, and row version column setup, you should be able to successfully append data from an Access query into a SQL Server table without encountering the “Record is deleted” error message. Remember to always verify your table structure and primary key configurations before attempting database operations.

In addition to these steps, we recommend checking out more advanced topics like:

  • How to modify table settings (e.g., autonumber, identity columns)
  • How to configure data types for single/double columns
  • How to optimize row version system usage

Feel free to ask if you need more help!


Last modified on 2024-04-03