views:

96

answers:

3

Is there anything like this:
TEST DELETE FROM user WHERE somekey = 45;

That can return any errors, for example that somekey doesn't exist, or some constraint violation or anything, and reporting how many rows would be affected, but not executing the query?
I know you can easily turn any query in a select query that has no write or delete effect in any row, but that can lead to errors and it's not very practical if you want to test and debug many queries.

+7  A: 

The only thing I know of is to wrap it in a transaction that is always rolled back:

BEGIN TRANSACTION

DELETE FROM user WHERE somekey = 45;

ROLLBACK TRANSACTION

Make sure you execute the entire block and not just the delete statement. Also, DO NOT run this on any production environment or any system where you cannot afford to lose the data.

NYSystemsAnalyst
A: 

To my knowledge no such thing exists. Furthermore it would not be an error if no somekey with value 45 did not exist. It would just not delete anything.

klausbyskov
I meant, just as an example, that a field typed in a query may not exist, or be misspelled, and that generates an SQL error.
Petruza
+2  A: 

ANSI SQL: No.

MySQL: Maybe. They EXPLAIN keyword original worked only with SELECT, but it might have been extended to UPDATE and DELETE by now.

Larry Lustig