This post going to be short and straight to the point 🙂 There are small compilation of 3 tips which can have positive impact on quality of your work.
- When doing UPDATE it is maybe usefull sometimes to see the results of updated value. It can be done by SQL OUTPUT command.
SET [email protected]
WHERE [email protected] AND tVal = @PVal
Result will be old value and new value
2. Sometimes it’s make sense to write set of queries as a transaction. For example you want to upgrade DB or part of it. So it may useful to wrap it up by following code:
SET XACT_ABORT ON
DECLARE @IsToCommit AS BIT = 1
… _WRITE_YOUR_SET_OF_QUERIES_ …
IF @IsToCommit = 0 BEGIN
PRINT ‘Changes are rolling back . @IsToCommit param needs to be changed to ”1” in order to commit.’
END ELSE BEGIN
PRINT ‘Changes have been committed.’
3. There situations in which we want to see if there additional usages of some specific column name. For that we can use INFORMATION_SCHEMA.COLUMNS :
–Check if any of the object( Table,View) has column name=’Address’
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
If you have any ideas, suggestions or you would love to share you own tips, write it down in a comments.