Click here to Skip to main content
15,850,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
suppose we want to insert a row to table but if column id > 5 then insertion don't be executed.(with using Triggers)

What I have tried:

create trigger trg_salesorder ON sales.orders instead of INSERT 
AS
SET NOCOUNT ON;
begin try 
	if id > 5 
		begin
			insert into sales.orders
		end
end try
begin catch 
	print 'id must be more than 5'
end catch
Posted
Updated 5-Dec-23 22:01pm
v2

1 solution

This sort of thing is best left to the application layer rather than a trigger, but if you insist then there is a worked example here - https://stackoverflow.com/questions/4255730/create-trigger-prevent-insert[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900