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 |
|
nagasundartn
Starting Member
3 Posts |
Posted - 2011-11-09 : 02:26:31
|
I have a table which contains minmum marks and maximum marks columns. The new row should be inserted with the following conditions:1. Minimum marks should be less then maximum marks2. The existing range of minimum and maximum marks should not fall on the newly inserted row range.Can anyone please explain the query with Triggers. T.N.Nagasundar |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 02:55:20
|
sounds like a check constraint is what you need. something likeALTER TABLE <tablename> ADD CONSTRAINT Chk_Marks CHECK ((MinMark <MaxMark) AND dbo.MarkRangeCount(MinMark,MaxMark) = 1 )MarkRangeCount function will be as followsCREATE FUNCTION MarkRangeCount(@MinMark int,@MaxMark int)RETURNS intASBEGIN DECLARE @Cnt intSELECT @Cnt = COUNT(*)FROM(SELECT *FROM TblWHERE (MinMark BETWEEN @MinMark AND @MaxMarkOR MaxMark BETWEEN @MinMark AND @MaxMark))tRETURN @CntEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|