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
 Other SQL Server 2008 Topics
 Making a trigger check result
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

skelle
Starting Member

1 Posts

Posted - 05/30/2012 :  14:54:01  Show Profile  Reply with Quote
Hello,

I want to make a trigger to check a result. That result may not be higher or equal to 20. When it is higher than 20, it has to be replaced by 20.

Someone out there who can help me?

robvolk
Most Valuable Yak

USA
15559 Posts

Posted - 05/30/2012 :  15:07:42  Show Profile  Visit robvolk's Homepage  Reply with Quote
It's better to have a CHECK constraint on the table that prevents values higher than 20 from being inserted or updated. Is this data being imported from a different source, or being entered by hand? If it's being imported then you should have an ETL process that changes higher values to 20, rather than having a trigger do it.

While a trigger can certainly do this, you could encounter performance issues, and it can't guarantee the data will be correct.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 06/04/2012 :  09:30:15  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Do you have data already in the table? You can just use a SELECT statement

select case when col>20 then 20 else col end as col from table

If you want to restrict the values while adding to table, better option is as suggested, to implement a check constraint

Madhivanan

Failing to plan is Planning to fail

Edited by - madhivanan on 06/04/2012 09:31:55
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.05 seconds. Powered By: Snitz Forums 2000