操作数类型冲突:uniqueidentifier 与 int 不兼容
当我尝试创建下面的存储过程时,出现以下错误:
操作数类型冲突:uniqueidentifier 与 int 不兼容
我不清楚是什么导致了此错误。 UserID 实际上是我所有表中的一个 int 。有人可以告诉我我做错了什么吗?
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
When I attempt to create the stored procedure below I get the following error:
Operand type clash: uniqueidentifier is incompatible with int
It's not clear to me what is causing this error. UserID is in fact an int in all of my tables. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,至少其中一个表已将
UserID
定义为uniqueidentifier
,而不是int
。你检查过每个表中的数据吗?SELECT TOP 1 UserID FROM
每个表会产生什么结果?int
还是GUID
?编辑
我认为您已经基于包含名为 UserID 的列的所有表构建了一个过程。我认为您不应该在脚本中包含
aspnet_Membership
表,因为它实际上并不是“您的”表之一。如果您打算围绕
aspnet_Membership
数据库设计表,那么当该表明确使用uniqueidentifier
时,为什么其余列是int
UserID
列?Sounds to me like at least one of those tables has defined
UserID
as auniqueidentifier
, not anint
. Did you check the data in each table? What doesSELECT TOP 1 UserID FROM
each table yield? Anint
or aGUID
?EDIT
I think you have built a procedure based on all tables that contain a column named UserID. I think you should not have included the
aspnet_Membership
table in your script, since it's not really one of "your" tables.If you meant to design your tables around the
aspnet_Membership
database, then why are the rest of the columnsint
when that table clearly uses auniqueidentifier
for theUserID
column?如果您通过视图访问此内容,则尝试
sp_recompile
或刷新视图。sp_recompile
:导致存储过程、触发器和用户定义函数在下次运行时重新编译。它通过从过程缓存中删除现有计划来强制在下次运行过程或触发器时创建新计划来实现此目的。在 SQL Server Profiler 集合中,记录事件 SP:CacheInsert,而不是事件 SP:Recompile。
参数
当前数据库中存储过程、触发器、表、视图或用户定义函数的限定或非限定名称。对象是 nvarchar(776),没有默认值。如果 object 是存储过程、触发器或用户定义函数的名称,则存储过程、触发器或函数将在下次运行时重新编译。如果 object 是表或视图的名称,则引用该表或视图的所有存储过程、触发器或用户定义函数将在下次运行时重新编译。
返回代码值
0(成功)或非零数字(失败)
备注
sp_recompile
仅在当前数据库中查找对象。存储过程、触发器和用户定义函数使用的查询仅在编译时才会优化。当对数据库进行索引或其他影响统计信息的更改时,编译的存储过程、触发器和用户定义的函数可能会降低效率。通过重新编译作用于表的存储过程和触发器,您可以重新优化查询。
If you're accessing this via a View then try
sp_recompile
or refreshing views.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.
Arguments
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. 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. 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.
Return Code Values
0 (success) or a nonzero number (failure)
Remarks
sp_recompile
looks for an object in the current database only.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.
原因是数据与数据类型不匹配。
我遇到了同样的问题,我忘记使字段匹配。虽然我的情况和你的不一样,但它显示了类似的错误消息。
情况是我复制了一张表,但不小心拼错了一个字段,所以我在创建数据库后使用
ALTER
更改了它。并且两个表中字段的顺序并不相同。因此,当我使用INSERT INTO TableName SELECT * FROM TableName
时,结果显示类似的错误:Operand type crash: datetime is incomplete with uniqueidentifier
这是一个简单的示例
:错误信息是:
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. And the order of fields in both table is not identical. so when I use theINSERT INTO TableName SELECT * FROM TableName
, the result showed the similar errors:Operand type clash: datetime is incompatible with uniqueidentifier
This is a simiple example:
The error message is: