Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqlmyworld
Starting Member
38 Posts |
Posted - 2013-07-18 : 19:38:55
|
Is there any way I can get noficiation when only one particular record of a table is updated/deleted. For business, the first record of a table let's say ID = 0 (record) is important and if some one updated that record then we will have some issues. I don't think a trigger can be created on a single record of a table. Is there any other solution for this scenario?Thanks in advance. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-07-18 : 19:43:53
|
You definitely could use a trigger. You can use @@ROWCOUNT combined with checking the inserted trigger table for the important record. If it finds that it occurred, you can write to a table and then you'd have a job that reads that table every minute and sends the email. Do not send email from the trigger, do it asynchronously so that the transaction completes as fast as possible.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
|
|
sqlmyworld
Starting Member
38 Posts |
Posted - 2013-07-18 : 21:08:32
|
Thanks Tara. Will follow instructions. |
|
|
sqlmyworld
Starting Member
38 Posts |
Posted - 2013-07-18 : 22:05:54
|
Hi Tata, one silly question - is that possible, only one record would be read only out of entire table rows. Let's say ID = 0 (record) is read only. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-19 : 01:04:50
|
quote: Originally posted by sqlmyworld Hi Tata, one silly question - is that possible, only one record would be read only out of entire table rows. Let's say ID = 0 (record) is read only.
you can create an instead of trigger to include logic that would avoid any modification to ID=0 record------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-19 : 01:21:26
|
[code]CREATE TRIGGER Trg_DataModificationON TableNameINSTEAD OF UPDATEASBEGIN IF EXISTS ( SELECT 1 FROM INSERTED WHERE ID <> 0 ) UPDATE t SET t.Col1=i.Col1, t.Col2 = i.Col2,... FROM Tbale t INNER JOIN INSERTED i ON i.PK = t.PK AND i.ID <> 0ENDPK is the primary key[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
sqlmyworld
Starting Member
38 Posts |
Posted - 2013-07-22 : 00:36:40
|
Thanks a lot Visakh |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-22 : 01:15:08
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|