Dreaded SQLs
Posted
by lavanyadeepak
on Geeks with Blogs
See other posts from Geeks with Blogs
or by lavanyadeepak
Published on Tue, 06 Apr 2010 14:58:45 GMT
Indexed on
2010/04/06
21:03 UTC
Read the original article
Hit count: 254
Dreaded SQLs
We used to think that a SQL statement without a where clause is only dangerous right since running that on a server TSQL is just going to impact the entire table like waving the magic wand. For that reason we should cultivate the habit first to write the statement as select and then to modify the select portion as update.
Within the T-SQL Window, I would normally prefer the following first:
select *
from employee
where empid in (4,5)
and then once I am satisfied with the results, I would go ahead with the following change:
--select *
delete
from employee
where empid in (4,5)
Today I just discovered another coding horror. This would typically be applicable in a stored procedure and with respect to variable nomenclature. It is always desirable to have a suitable nomenclature for parameters distinct from the column names and internal variables. This would help quicker debugging of the stored procedures besides enhancing the readability. Else in a quick bout of enthusiasm a statement like
if (@CustomerID = @CustomerID) [when the latter is intended to denote the column name and there is a superflous @ prepended], zeroing in on the problem would be little tricky. Had there been a still powerful nomenclature rules then debugging would have been more straight-forward and simpler right?
© Geeks with Blogs or respective owner