SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Single Record Notification
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlmyworld
Starting Member

Australia
38 Posts

Posted - 07/18/2013 :  19:38:55  Show Profile  Reply with Quote
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

USA
36636 Posts

Posted - 07/18/2013 :  19:43:53  Show Profile  Visit tkizer's Homepage  Reply with Quote
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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sqlmyworld
Starting Member

Australia
38 Posts

Posted - 07/18/2013 :  21:08:32  Show Profile  Reply with Quote
Thanks Tara. Will follow instructions.
Go to Top of Page

sqlmyworld
Starting Member

Australia
38 Posts

Posted - 07/18/2013 :  22:05:54  Show Profile  Reply with Quote
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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/19/2013 :  01:04:50  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/19/2013 :  01:21:26  Show Profile  Reply with Quote

CREATE TRIGGER Trg_DataModification
ON TableName
INSTEAD OF UPDATE
AS
BEGIN
  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 <> 0
END

PK is the primary key


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sqlmyworld
Starting Member

Australia
38 Posts

Posted - 07/22/2013 :  00:36:40  Show Profile  Reply with Quote
Thanks a lot Visakh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/22/2013 :  01:15:08  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000