Unix Technical Forum

512 error in delete statement

This is a discussion on 512 error in delete statement within the SQL Server forums, part of the Microsoft SQL Server category; --> I have a piece of code that uses the db-library with sql server 2000/2005 and runs the following delete ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-04-2008, 07:23 AM
phdscholar80@yahoo.com
 
Posts: n/a
Default 512 error in delete statement

I have a piece of code that uses the db-library with sql server
2000/2005 and runs the following delete statement:



DELETE FROM TABLE1 WHERE COL1 IN( 'Some Val1' ) AND COL2 IN( 'Some
Val2' ) AND Col3 IN( integer1 ) AND Col4 IN( integer2 ) AND Col5
IN( 'Some Val3' )



on TABLE1, uploads data into TABLE1 through bulk loading, calls a
stored procedure that uses the data, and then deletes the data through
the SAME delete statement with EXACTLY the same parameter values. The
first delete statement is always successful, but the second statement
intermittently gives the following error:



0,0,MS SQL Server Message :
SQL Server message 512, state 1, severity 16:
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.
SQL Server message 3621, state 0, severity 0:
The statement has been terminated.

Note: I was initially using the equality operator instead of the IN
operator in the query but that gave the same results.

The table has the schema

Table1( Col1 varchar(50) NULL, Col2 varchar(50) NULL, Col3 int NULL,
Col4 int NULL, Col5 varchar(128) NULL, Col6 varchar(128) NULL, Col7
varchar(100) NULL, Col8 varchar(50) NULL, Col9 varchar(50) NULL,
Col10 int NULL, Col11 int NULL, Col12 float NULL, Col13 float NULL,
Col14 float NULL, Col15 float NULL )

Can somebody tell me whats going wrong here? I can easily ignore this
error because my work is done after the stored proc but I fear
amassing a lot of useless data in the table over time. Also
http://support.microsoft.com/kb/195491 talks about a case where the
delete statement is actually successful but still causes an error when
using ADO. I vaguely remember hearing somewhere that delete causes a
lot of problems if the table doesn't have primary keys. Is this
correct?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-04-2008, 07:23 AM
Dan Guzman
 
Posts: n/a
Default Re: 512 error in delete statement

> Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as
> an expression.


Since your DELETE statement has no subqueries, my guess is that you have a
DELETE trigger on the table that is causing this error. In that case,
examine and correct the trigger code.


--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<phdscholar80@yahoo.com> wrote in message
news:abf71715-4fdc-4ad1-bff1-5b504d5b124f@i29g2000prf.googlegroups.com...
>I have a piece of code that uses the db-library with sql server
> 2000/2005 and runs the following delete statement:
>
>
>
> DELETE FROM TABLE1 WHERE COL1 IN( 'Some Val1' ) AND COL2 IN( 'Some
> Val2' ) AND Col3 IN( integer1 ) AND Col4 IN( integer2 ) AND Col5
> IN( 'Some Val3' )
>
>
>
> on TABLE1, uploads data into TABLE1 through bulk loading, calls a
> stored procedure that uses the data, and then deletes the data through
> the SAME delete statement with EXACTLY the same parameter values. The
> first delete statement is always successful, but the second statement
> intermittently gives the following error:
>
>
>
> 0,0,MS SQL Server Message :
> SQL Server message 512, state 1, severity 16:
> Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as
> an expression.
> SQL Server message 3621, state 0, severity 0:
> The statement has been terminated.
>
> Note: I was initially using the equality operator instead of the IN
> operator in the query but that gave the same results.
>
> The table has the schema
>
> Table1( Col1 varchar(50) NULL, Col2 varchar(50) NULL, Col3 int NULL,
> Col4 int NULL, Col5 varchar(128) NULL, Col6 varchar(128) NULL, Col7
> varchar(100) NULL, Col8 varchar(50) NULL, Col9 varchar(50) NULL,
> Col10 int NULL, Col11 int NULL, Col12 float NULL, Col13 float NULL,
> Col14 float NULL, Col15 float NULL )
>
> Can somebody tell me whats going wrong here? I can easily ignore this
> error because my work is done after the stored proc but I fear
> amassing a lot of useless data in the table over time. Also
> http://support.microsoft.com/kb/195491 talks about a case where the
> delete statement is actually successful but still causes an error when
> using ADO. I vaguely remember hearing somewhere that delete causes a
> lot of problems if the table doesn't have primary keys. Is this
> correct?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 07:23 AM
Erland Sommarskog
 
Posts: n/a
Default Re: 512 error in delete statement

(phdscholar80@yahoo.com) writes:
> I have a piece of code that uses the db-library with sql server
> 2000/2005 and runs the following delete statement:


Beware that DB-Library is deprecated, and the version after SQL 2008
will not permit connections for DB-Library. Also, with DB-Library
you don't access to a lot of the new functionality added in SQL 7 and
later.

> on TABLE1, uploads data into TABLE1 through bulk loading, calls a
> stored procedure that uses the data, and then deletes the data through
> the SAME delete statement with EXACTLY the same parameter values. The
> first delete statement is always successful, but the second statement
> intermittently gives the following error:
>
>
>
> 0,0,MS SQL Server Message :
> SQL Server message 512, state 1, severity 16:
> Subquery returned more than 1 value. This is not permitted when the
> subquery follows =, !=, <, <= , >, >= or when the subquery is used as
> an expression.


As Dan said, the cause is likely to be found in a poorly written trigger.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:41 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com