July 9, 2018 at 10:12 am
I have a database and i would like to create a trigger which will not allow a user to update a customers name and will provide a message explaining the block
I have been able to successfully create the message trigger however need help creating the update prevention trigger.
Find below my message trigger:
[Create trigger [dbo].[CustomerErrorMessage]
on [dbo].[tblCustomer]
after update
as
begin
print 'Sorry, unable to update customer name'
end ]
Please find below the database sample:
July 9, 2018 at 10:49 am
Nqobilemoyo - Monday, July 9, 2018 10:12 AMI have a database and i would like to create a trigger which will not allow a user to update a customers name and will provide a message explaining the blockI have been able to successfully create the message trigger however need help creating the update prevention trigger.
Find below my message trigger:
[Create trigger [dbo].[CustomerErrorMessage]
on [dbo].[tblCustomer]
after update
as
begin
print 'Sorry, unable to update customer name'
end ]Please find below the database sample:
Use ROLLBACK TRANSACTION.
July 9, 2018 at 11:22 am
Nqobilemoyo - Monday, July 9, 2018 10:12 AMI have a database and i would like to create a trigger which will not allow a user to update a customers name and will provide a message explaining the blockI have been able to successfully create the message trigger however need help creating the update prevention trigger.
Find below my message trigger:
[Create trigger [dbo].[CustomerErrorMessage]
on [dbo].[tblCustomer]
after update
as
begin
print 'Sorry, unable to update customer name'
end ]Please find below the database sample:
Don't use an AFTER trigger for this. Use an INSTEAD OF trigger, instead. (pun intended).
--Jeff Moden
Change is inevitable... Change for the better is not.
July 10, 2018 at 9:24 am
You can use the UPDATE() or COLUMNS_UPDATED() functions to check if the column has changed. Or use a query to compare inserted.customername with deleted.customername.
July 10, 2018 at 11:43 am
If the app/person/whatever doing the UPDATE is not a sysadmin, (or perhaps a dbo, not sure on that one), maybe you can just DENY UPDATE on that column:
DENY UPDATE ON dbo.tblCustomer ( customer_name ) TO public|<user[,...]>;
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply