views:

207

answers:

2

Hi I dont have any idea why am i getting this error :-

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

I was trying to run this query:-

ALTER TABLE Test1 NOCHECK CONSTRAINT ALL
ALTER TABLE Test2 NOCHECK CONSTRAINT ALL


UPDATE Test1 
SET ID= '05f6c6b4-63ff-45b2-a5e2-920d5dce3e45' 
WHERE ID = '05e6c6b4-63ff-45b2-a5e2-920d5dce3e45'; 
UPDATE Test2 
SET ID = '05f6c6b4-63ff-45b2-a5e2-920d5dce3e45' ,
SpecID = NULL ,
RefLastName = 'Dummy' ,
RefFirstName = 'First Name' ,
RefMiddleName = NULL ,
RefPhone1 = '111444444' ,
RefPhone2 = '2121222' ,
RefFax = '222222' ,
RefEmail = '[email protected]' 
WHERE 
RefID = '05e6c6b4-63ff-45b2-a5e2-920d5dce3e45' 

ALTER TABLE Test1 WITH CHECK CHECK CONSTRAINT ALL
ALTER TABLE Test2 WITH CHECK CHECK CONSTRAINT ALL
A: 

Looks like you need a semicolon to end this statement:

 UPDATE Test  
 SET RefID = '05f6c6b4-63ff-45b2-a5e2-920d5dce3e45' 
 WHERE RefID = '05e6c6b4-63ff-45b2-a5e2-920d5dce3e45'; 

 UPDATE RefPhysician 
 SET RefID = '05f6c6b4-63ff-45b2-a5e2-920d5dce3e45' ,
 SpecID = NULL ,
 RefLastName = 'DR. BRAD DIBBLE' ,
 RefFirstName = 'First Name' ,
 RefMiddleName = NULL ,
 RefPhone1 = '613444444' ,
 RefPhone2 = 'print,read,866,1' ,
 RefFax = '6476476464' ,
 RefEmail = '[email protected]' 
 WHERE RefID = '05e6c6b4-63ff-45b2-a5e2-920d5dce3e45'  ; <-- semicolon
Kai
it didn't work.
Novice
Well, just to be sure, try ending every SQL statement with a semicolon.
Robert Harvey
+5  A: 

Does one of the tables you are updating have a trigger? If it does, likely it contains a subquery with more than one value.

Personally I find it a very bad practice to turn check constraints off when doing inserts or updates. They are there for a reason and if your data doesn't meet those constraints, it should not be inserted as is or the constraint needs to be adjusted for new conditions. It can also create problems if the records is updated in the future.

HLGEM
Thanks for the clue. Error was because of the Trigger. BTW, I agree that this is a bad practice. But I think thats how I can achieve my task of Synchronizing an old database with the new database (Updated one. Drastic change in Table structures). In new database, all GUIDs are new. :(
Novice
I strongly suggest you consider altering your trigger to handle multiple updates or raising a more meaningful error if multiple rows are in the sub-select.
Cade Roux
He must be modifying the columns on both sides of an FK constraint. Only way to do that without disabling them (that I can think of, assuming NOT NULL columns) is to make a new entry in table A, update table B to point to the new entry in A, then delete the old entry in A.
Philip Kelley
For now, i am disabling/enabling Triggers before updating. It is working fine.
Novice
Please also think twice about disabling the triggers. If you have bad code in the trigger as it appears you do, it needs to be fixed ASAP. Bad trigger code is a extremely serious bug.
HLGEM
It's also posible someone ELSE could be doing an insert that SHOULD have the triggers while you've disabled them.
n8wrl