添加 rowguid 列破坏了这个存储过程?
下面的存储过程不允许我添加它来修改它。 当尝试修改它时,我收到以下错误 -->
消息 213,级别 16,状态 1,过程 spPersonRelationshipAddOpducing,第 51 行 插入错误:列名称或提供的值的数量与表定义不匹配。
此外,由于数据库是为 Merge Rep 设置的(已添加 rowguid 列),因此该存储过程现在不再正常工作。
我需要更改列的列出方式吗? 设置合并代表时的警告之一是 -->
添加 Guid 列可能会导致没有列列表的 INSERT 语句失败
这是什么意思? 我该如何解决?
USE [Connect]
GO
/****** Object: StoredProcedure [dbo].[spPersonRelationshipAddOpposing] Script Date: 07/15/2009 08:14:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spPersonRelationshipAddOpposing]
@ExistingRelationshipID INT
AS
BEGIN
--Declare local variables
DECLARE @PersonID INT --PersonID of established relarionship
DECLARE @RelatedID INT --RelatedID of established relarionship
DECLARE @Relationship VARCHAR(4) --Established relarionship
DECLARE @RelatedSex as VARCHAR(1)
DECLARE @OpposingRelationship VARCHAR(4)
DECLARE @OpposingRelationshipID INT
--Fill variables from existing relationship
SELECT @PersonID = PersonID, @RelatedID = RelatedID, @Relationship=PersonRelationshipTypeID
FROM tblPersonRelationship where PersonRelationshipID = @ExistingRelationshipID
--Get gender of relative for finding opposing relationship type
SELECT @RelatedSex = (SELECT Gender FROM tblPerson WHERE PersonID = @PersonID)
--get opposing relationship types
IF (@RelatedSex='M')
BEGIN
SELECT @OpposingRelationship = (SELECT OpposingMaleRelationship
From tblAdminPersonRelationshipType
WHERE PersonRelationshipTypeID = @Relationship)
END
ELSE IF (@RelatedSex='F')
BEGIN
SELECT @OpposingRelationship = (SELECT OpposingFemaleRelationship
From tblAdminPersonRelationshipType
WHERE PersonRelationshipTypeID = @Relationship)
END
--check for existing opposing relationship
SELECT @OpposingRelationshipID = (SELECT MAX(PersonRelationshipID) FROM tblPersonRelationship WHERE PersonID = @RelatedID AND RelatedID = @PersonID)
--if an opposing relationship was found
IF (@OpposingRelationship IS NOT NULL)
BEGIN
--if there is a relationship, update it
IF ISNUMERIC(@OpposingRelationshipID)=1
BEGIN
UPDATE tblPersonRelationship
SET PersonRelationshipTypeID = @OpposingRelationship,
MarriageDate = (SELECT MarriageDate FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
ResidesWithPersonFlag = (SELECT ResidesWithPersonFlag FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateDateTime = (SELECT UpdateDateTime FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateProgram = (SELECT UpdateProgram FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateUserID = (SELECT UpdateUserID FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID)
WHERE PersonRelationshipID = @OpposingRelationshipID
END
--otherwise add record
ELSE IF (@OpposingRelationship IS NOT NULL)
BEGIN
INSERT INTO tblPersonRelationship
SELECT @RelatedID, @OpposingRelationship, @PersonID,
MarriageDate, NULL, NULL,
ResidesWithPersonFlag, NULL, UpdateDateTime, UpdateProgram,
UpdateUserID, UpdateDateTime, UpdateProgram,
UpdateUserID, NULL FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID
END
END
END
The below stored procedure will not allow me to add it to Modify it. When attempting to modify it I get the following error -->
Msg 213, Level 16, State 1, Procedure spPersonRelationshipAddOpposing, Line 51
Insert Error: Column name or number of supplied values does not match table definition.
Also, Since the DB was set up for Merge Rep (a rowguid column has been added) this stored procedure now no longer works properly.
Do I need to change the way the columns are listed? One of the warnings when setting up Merge Rep was this -->
Adding Guid Column MAY Cause INSERT Statements without column lists to Fail
What does that mean? How do I fix this?
USE [Connect]
GO
/****** Object: StoredProcedure [dbo].[spPersonRelationshipAddOpposing] Script Date: 07/15/2009 08:14:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spPersonRelationshipAddOpposing]
@ExistingRelationshipID INT
AS
BEGIN
--Declare local variables
DECLARE @PersonID INT --PersonID of established relarionship
DECLARE @RelatedID INT --RelatedID of established relarionship
DECLARE @Relationship VARCHAR(4) --Established relarionship
DECLARE @RelatedSex as VARCHAR(1)
DECLARE @OpposingRelationship VARCHAR(4)
DECLARE @OpposingRelationshipID INT
--Fill variables from existing relationship
SELECT @PersonID = PersonID, @RelatedID = RelatedID, @Relationship=PersonRelationshipTypeID
FROM tblPersonRelationship where PersonRelationshipID = @ExistingRelationshipID
--Get gender of relative for finding opposing relationship type
SELECT @RelatedSex = (SELECT Gender FROM tblPerson WHERE PersonID = @PersonID)
--get opposing relationship types
IF (@RelatedSex='M')
BEGIN
SELECT @OpposingRelationship = (SELECT OpposingMaleRelationship
From tblAdminPersonRelationshipType
WHERE PersonRelationshipTypeID = @Relationship)
END
ELSE IF (@RelatedSex='F')
BEGIN
SELECT @OpposingRelationship = (SELECT OpposingFemaleRelationship
From tblAdminPersonRelationshipType
WHERE PersonRelationshipTypeID = @Relationship)
END
--check for existing opposing relationship
SELECT @OpposingRelationshipID = (SELECT MAX(PersonRelationshipID) FROM tblPersonRelationship WHERE PersonID = @RelatedID AND RelatedID = @PersonID)
--if an opposing relationship was found
IF (@OpposingRelationship IS NOT NULL)
BEGIN
--if there is a relationship, update it
IF ISNUMERIC(@OpposingRelationshipID)=1
BEGIN
UPDATE tblPersonRelationship
SET PersonRelationshipTypeID = @OpposingRelationship,
MarriageDate = (SELECT MarriageDate FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
ResidesWithPersonFlag = (SELECT ResidesWithPersonFlag FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateDateTime = (SELECT UpdateDateTime FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateProgram = (SELECT UpdateProgram FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID),
UpdateUserID = (SELECT UpdateUserID FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID)
WHERE PersonRelationshipID = @OpposingRelationshipID
END
--otherwise add record
ELSE IF (@OpposingRelationship IS NOT NULL)
BEGIN
INSERT INTO tblPersonRelationship
SELECT @RelatedID, @OpposingRelationship, @PersonID,
MarriageDate, NULL, NULL,
ResidesWithPersonFlag, NULL, UpdateDateTime, UpdateProgram,
UpdateUserID, UpdateDateTime, UpdateProgram,
UpdateUserID, NULL FROM tblPersonRelationship WHERE PersonRelationshipID = @ExistingRelationshipID
END
END
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在过程的最后,您将看到以下 INSERT:
如果您向 tblPersonRelationship 添加一列,此代码将会中断。 因此,您需要将此代码替换为以下内容:
“您为其提供值的列列表”是指 SELECT 中的值列表:
因为您没有为 rowguid 提供值,所以请勿将其包含在列表中列。
At the very end of your procedure you have the following INSERT:
This code will break if you add one more column to tblPersonRelationship. So you need to replace this code with the following:
by "list of columns you are providing values for" I mean the list of values in your SELECT:
Because you do not provide a value for your rowguid, do not include it in the list of columns.
继续您的其他(已删除)问题,让我们剖析该错误消息:
我检查了插入语句两侧的值的数量,它们匹配,所以不是这样。 而且 sql server 并不关心 VALUES 列表中的列名,所以不是这样。 这意味着
INSERT
列表中的列名之一是错误的。 那里有很多名字——你检查过没有拼写错误吗?Continued from your other (deleted) question, let's dissect that error message:
I checked the number of values in both sides of the insert statement and they match, so that's not it. And sql server doesn't care about the column names in the
VALUES
list, so that's not it. This means that one of the column names in theINSERT
list is wrong. You have a lot of names there — have you checked that you don't have a typo somewhere?我相信您可能需要从发布者“推送”架构更改,而不是尝试从客户端拉取它们。
按照此处的联机丛书说明中针对您的特定复制拓扑修改文章的过程:
http://msdn.microsoft.com/en-us/library/ms152493(SQL.90).aspx
让我知道您的进展如何。
I bleieve you may need to "push" the schema changes from the Publisher, as opposed to attempt to pull them from the client.
Follow the process for modifying an Article, for your specific replication topology, from the Books Online instruction here:
http://msdn.microsoft.com/en-us/library/ms152493(SQL.90).aspx
Let me know how you get on.
在执行 INSERT 时,您应该始终显式指定列的列表。
像这样重写您的代码:
隐式添加 guid 列以支持合并复制,这就是您收到有关列列表不匹配的错误的原因。
You should always specify explicitly the list of columns when doing the INSERT.
Rewrite your code like this:
A guid column was implicitly added to support merge replication, that's why you got the error about column lists mismatch.
当提供的列名称的数量或提供的值的数量与表定义不匹配时,在 INSERT 操作期间会出现此错误消息(插入错误:列名称或提供的值的数量与表定义不匹配)。
我认为您正在处理后者 - 提供的值的数量与表定义不匹配。这是我的预感,基于您注意到 rowguid 列已添加到您的一个表中这一事实。
例如,我们将插入到 tblPersonRelationship 中。 根据 SELECT,我们应该假设 tblPersonRelationship 有 15 个非默认列。 如果您添加了 rowguid 列,那么它现在需要在 SELECT 中的正确位置表示。
在处理计算列时,您也可能会收到此错误。 我不认为这是您的问题,但您可以在这里找到更多信息< /a>.
This error message (Insert Error: Column name or number of supplied values does not match table definition) appears during an INSERT operation when either the number of supplied column names or the number of supplied values does not match the table definition.
I think you are dealing with the latter -- the number of supplied values does not match the table definition. That's my hunch based on the fact that you noted a rowguid column has been added to one of your tables.
Let's take your insert into tblPersonRelationship, for example. Based on the SELECT, one should assume tblPersonRelationship has 15 non-defaulted columns. If you added a rowguid column, it now needs to be represented in the SELECT in the proper position.
You may also get this error when dealing with computed columns. I don't believe this to be your issue, but you may find more here.
Guid 列的scope_identity()? 不,您必须做更多的工作才能获得新的指南。
首先,您必须创建一个表变量:
然后您必须将其放在插入语句的中间。
然后您可以从表变量中检索值。
scope_identity() for a Guid column? No you have to do a lot more work to get the new guid.
First you have to create a table variable:
Then you have to put that in the middle of your insert statement.
Then you can retrieve the value from the table variable.