March 25, 2009 at 8:11 pm
Hi All,
I have written some sql queries for insertion and updation of the records on a table.
Before executing the query how can I make sure the query that I wrote is correct.
Is there any specific way to ensure that the code written by me is with out errors.
Thanks,
Sandhya
March 25, 2009 at 9:04 pm
First, you should be working in a development/test environment and testing your queries before ever getting them even close to a production system.
Next, you can wrap the process in a transaction - and put checks in place to confirm that the code is correct. For example:
BEGIN TRANSACTION;
INSERT INTO dbo.InsertTable ({columns})
SELECT {columns}
FROM dbo.OtherTable
JOIN ...
WHERE ...
-- validate insert is correct
SELECT * FROM ...
ROLLBACK TRANSACTION;
By wrapping in a transaction and rolling it back - you can test whether or not you insert/update affects the right numbers of rows, makes the expected changes, etc... and does not actually make any changes.
Once everything is validated - change the rollback to a commit and run the final version.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
March 28, 2009 at 12:40 am
[font="Verdana"]
sandhyarao49 (3/25/2009)
Hi All,I have written some sql queries for insertion and updation of the records on a table.
Before executing the query how can I make sure the query that I wrote is correct.
Is there any specific way to ensure that the code written by me is with out errors.
Thanks,
Sandhya
I think you better compile your statements before putting them either in SProc / Function etc. You can directly execute such queries on the testing evironment, if you have. You will be guided over there in Query analyzer whether the queries qritten by you are errorless.
Mahesh[/font]
MH-09-AM-8694
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply