SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Track Updates in Quantity Field


Track Updates in Quantity Field

Author
Message
zeeshandar
zeeshandar
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 139
Hi,

Thanks for your time.
I only have basic info about Sql Server database handling. What I need to do is:

I have a table containing stock quantity. What I need to do is whenever quantity changes in Stock field, database send an email to me.

Please advice.

Thanks!
Zeeshan
ColdCoffee
ColdCoffee
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3651 Visits: 5548
You may want to read about Triggers which do exactly what you wanted!

Link : DML Triggers
vikingDBA
vikingDBA
SSC-Addicted
SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)

Group: General Forum Members
Points: 414 Visits: 929
Also, if you want that trigger to send you email, you will need to turn on Database Mail (DBMail) in order to use it.

To get you started, here is a simple script to send a message, once DBMail is turned on and set up.

--simple message
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQL Server Agent Mail Profile', -- this should be the actual profile name you give it when set up
@recipients = 'someaddres@somecompany.com', -- use ; between them if more than one
@body = 'This is a test of the emergency broadcast system....',
@subject = 'This is only a test' ;
Steve Jones
Steve Jones
SSC Guru
SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)SSC Guru (61K reputation)

Group: Administrators
Points: 61635 Visits: 19099
Be careful with this. Lots of people start out with this requirement and once they 50 emails in an hour, they decide it was a bad idea.

What you might want is to track the changes in another table, and then periodically send out an update to yourself. Or only send an update if there hasn't been another update sent in the last hour.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
vikingDBA
vikingDBA
SSC-Addicted
SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)

Group: General Forum Members
Points: 414 Visits: 929
I agree totally. I would recommend adding an audit table, and keep track of changes there by using a trigger to insert the important information to the audit table (who, what, when).

Then you can just do a select when you want to find the information.
Eugene Elutin
Eugene Elutin
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4960 Visits: 5478
Having a SQL trigger sending email when data is changed is not a good idea.
However, you may still want to get email ASAP, faster than periodic job...
You can follow the previous advise to create a trigger which audit the changes into another table. Then design a service which pools the table and sends emails...

Beeing in SQL2008, instead of triggers you may be interesting to try in-built CDC (change tracking)

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search