简体   繁体   English

操作数类型冲突:uniqueidentifier与int不兼容

[英]Operand type clash: uniqueidentifier is incompatible with int

When I attempt to create the stored procedure below I get the following error: 当我尝试在下面创建存储过程时,出现以下错误:

Operand type clash: uniqueidentifier is incompatible with int 操作数类型冲突:uniqueidentifier与int不兼容

It's not clear to me what is causing this error. 我不清楚导致此错误的原因。 UserID is in fact an int in all of my tables. UserID实际上是我所有表中的int。 Can someone tell me what I've done wrong? 有人可以告诉我我做错了什么吗?

create procedure dbo.DeleteUser(@UserID int)
as

    delete from [aspnet_Membership] where UserId = @UserID
    delete from [Subscription] where UserID = @UserID
    delete from [Address] where UserID = @UserID
    delete from [User] where UserID = @UserID

go

Sounds to me like at least one of those tables has defined UserID as a uniqueidentifier , not an int . 在我看来,至少这些表之一已将UserID定义为uniqueidentifier ,而不是int Did you check the data in each table? 您是否检查了每个表中的数据? What does SELECT TOP 1 UserID FROM each table yield? 每个表中的SELECT TOP 1 UserID FROM产生什么? An int or a GUID ? 一个int还是GUID

EDIT 编辑

I think you have built a procedure based on all tables that contain a column named UserID. 我认为您已经基于包含名为UserID的列的所有表构建了一个过程。 I think you should not have included the aspnet_Membership table in your script, since it's not really one of "your" tables. 我认为您不应该在脚本中包含aspnet_Membership表,因为它实际上不是“您的”表之一。

If you meant to design your tables around the aspnet_Membership database, then why are the rest of the columns int when that table clearly uses a uniqueidentifier for the UserID column? 如果您打算围绕aspnet_Membership数据库设计表,那么当该表明确为UserID列使用uniqueidentifier时,为什么其余的aspnet_Membership int呢?

If you're accessing this via a View then try sp_recompile or refreshing views. 如果要通过视图访问此视图,请尝试sp_recompile或刷新视图。

sp_recompile : sp_recompile

Causes stored procedures, triggers, and user-defined functions to be recompiled the next time that they are run. 使存储过程,触发器和用户定义的函数在下次运行时重新编译。 It does this by dropping the existing plan from the procedure cache forcing a new plan to be created the next time that the procedure or trigger is run. 它是通过从过程高速缓存中删除现有计划来强制下一次运行该过程或触发器时创建一个新计划的。 In a SQL Server Profiler collection, the event SP:CacheInsert is logged instead of the event SP:Recompile. 在SQL Server Profiler集合中,记录了事件SP:CacheInsert而不是事件SP:Recompile。

Arguments 争论

[ @objname= ] 'object'

The qualified or unqualified name of a stored procedure, trigger, table, view, or user-defined function in the current database. 当前数据库中存储过程,触发器,表,视图或用户定义函数的合格或不合格名称。 object is nvarchar(776), with no default. 对象是nvarchar(776),没有默认值。 If object is the name of a stored procedure, trigger, or user-defined function, the stored procedure, trigger, or function will be recompiled the next time that it is run. 如果object是存储过程,触发器或用户定义函数的名称,则存储过程,触发器或函数将在下次运行时重新编译。 If object is the name of a table or view, all the stored procedures, triggers, or user-defined functions that reference the table or view will be recompiled the next time that they are run. 如果object是表或视图的名称,则所有引用该表或视图的存储过程,触发器或用户定义的函数都将在下次运行时重新编译。

Return Code Values 返回码值

0 (success) or a nonzero number (failure) 0(成功)或非零数字(失败)

Remarks 备注

sp_recompile looks for an object in the current database only. sp_recompile仅在当前数据库中查找对象。

The queries used by stored procedures, or triggers, and user-defined functions are optimized only when they are compiled. 存储过程或触发器使用的查询以及用户定义的函数仅在编译时才进行优化。 As indexes or other changes that affect statistics are made to the database, compiled stored procedures, triggers, and user-defined functions may lose efficiency. 当对数据库进行影响统计的索引或其他更改时,编译的存储过程,触发器和用户定义的函数可能会降低效率。 By recompiling stored procedures and triggers that act on a table, you can reoptimize the queries. 通过重新编译作用在表上的存储过程和触发器,可以重新优化查询。

The reason is that the data doesn't match the datatype. 原因是数据与数据类型不匹配。 I have come across the same issues that I forgot to make the fields match. 我遇到了我忘记使字段匹配的相同问题。 Though my case is not same as yours, but it shows the similar error message. 尽管我的情况与您的情况不同,但它显示了类似的错误消息。

The situation is that I copy a table, but accidently I misspell one field, so I change it using the ALTER after creating the database. 情况是我复制了一个表,但是偶然地我拼错了一个字段,因此在创建数据库后使用ALTER对其进行了ALTER And the order of fields in both table is not identical. 并且两个表中的字段顺序都不相同。 so when I use the INSERT INTO TableName SELECT * FROM TableName , the result showed the similar errors: Operand type clash: datetime is incompatible with uniqueidentifier 因此,当我使用INSERT INTO TableName SELECT * FROM TableName ,结果显示类似的错误: Operand type clash: datetime is incompatible with uniqueidentifier

This is a simiple example: 这是一个类似的示例:

use example
go
create table Test1 (
    id int primary key,
    item uniqueidentifier,
    inserted_at datetime
    )
go
create table Test2 (
    id int primary key,
    inserted_at datetime
    )
go
alter table Test2 add item uniqueidentifier;
go

--insert into Test1 (id, item, inserted_at) values (1, newid(), getdate()), (2, newid(), getdate());


insert into Test2 select * from Test1;

select * from Test1;
select * from Test2;


The error message is: 错误消息是:

Msg 206, Level 16, State 2, Line 24
Operand type clash: uniqueidentifier is incompatible with datetime

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 操作数类型冲突:uniqueidentifier与查询中的int不兼容 - Operand type clash: uniqueidentifier is incompatible with int in query 操作数类型冲突:uniqueidentifier 与 float 不兼容 - Operand type clash: uniqueidentifier is incompatible with float 尝试在参数中添加“ ALL”选项时,操作数类型冲突uniqueidentifier与int不兼容 - operand type clash uniqueidentifier is incompatible with int when trying to add 'ALL' option to my parameter 存储过程-操作数类型冲突:smallint与uniqueidentifier不兼容 - Stored procedure - Operand type clash: smallint is incompatible with uniqueidentifier 操作数类型冲突:日期与int不兼容? - Operand type clash: date is incompatible with int? 操作数类型冲突:int与utblProgramAllotment [用户定义的表类型]不兼容 - operand type clash: int is incompatible with utblProgramAllotment[user defined table type] 如何修复错误 - 操作数类型冲突:日期与 int 不兼容 - How to fix the error - Operand type clash: date is incompatible with int 操作数类型clash int与sql server中的日期不兼容 - operand type clash int is incompatible with date in sql server SQL Server 2012(触发器)操作数类型冲突:int与日期不兼容 - SQL Server 2012 (triggers) Operand type clash: int is incompatible with date 存储过程操作数类型冲突:日期与int不兼容 - Stored Procedure Operand type clash: date is incompatible with int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM