INSERT / UPDATE语句与外键约束冲突

时间:2018-11-22 09:31:45

标签: c# sql ms-access database-migration

我一直在从Access db-> Azure SQL服务器进行数据库迁移。 我已经重新创建了所有OleDbCommandSqlCommand。例如...

 private bool WriteCustomerComment(int customerID, string comment)
    {
        var sqlQuery = "INSERT INTO CustomerComment (CustomerID, Comment) VALUES (?, ?)";
        var parameters = new object[]
        {
            customerID, comment
        };

        return ExecuteNonQuery(sqlQuery, parameters);
    }

已经成为...

 private bool WriteCustomerComment(int customerID, string comment)
    {
        var parameterList = new List<SqlParameter>();
        var sqlQuery = "INSERT INTO CustomerComment (CustomerID, Comment) VALUES (@customerId, @comment)";

        parameterList.Add(new SqlParameter("@customerId", customerID));
        parameterList.Add(new SqlParameter("@comment", comment));

        return ExecuteNonQuery(sqlQuery, parameterList);
    }

现在。所有程序都运行良好,但随后我尝试使用“ SQL Server迁移助手”(来自Microsoft,旨在处理对SQL迁移的访问)进行迁移。 因为使用内置的“ Microsoft SQL Server Management Studio”进行迁移没有转移

*主键

*外键

*表绑定

*约束等。

当我这样做时,它转移了上述所有内容。但是,当我再次尝试时,程序开始出现问题。当我在所需的字段中输入值时,它却给了我以下内容...

The INSERT Statement conflicted with the Foreign Key constraint "Sample$CustomerSample". Table dbo.Customer, Column "CustomerID". 

关于我正在创建哪种测试,此错误消息有所不同。该语句也可以是

The UPDATE statement conflicted with the Foreign Key constraint.....

现在我已经尝试过在线获取一些信息,但是我真的不知道如何解决这个问题。这是否会成为所关注表中的某种脚本/更改?还是迁移中的问题?我发现告诉我键等在Access和SQL中的行为应相同?

以下是“客户”表的图片。

enter image description here

0 个答案:

没有答案
相关问题