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 |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-05-15 : 15:30:18
|
| HiI have a table with 3 columns in it. The ID column has a datetime data type.Does anyone know how to apply a check constraint on this field so that the same month cannot be entered twice.For example the field has the following data in the field26/04/200827/05/200826/06/200825/07/2008A user then tries to enter the value 20/05/2008, I would like the check constraint to block this value being entered due to the fact that a item with the same month value has already been entered.Is this possible?Thanking you in Advance!!! |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-05-15 : 18:28:55
|
| You can't do this with a check constraint, because they only look at columns within the same row, and you want to check for unique months between rows.You would have to use a unique constraint on a column in the table or in a view.CODO ERGO SUM |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-15 : 18:32:45
|
| I suppose you could also use a trigger if you are unable to modify the schema. The trigger would check for the issue and rollback if found.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-05-16 : 03:27:35
|
| HIThanks for that, I was thinking about using a trigger, but wasn't sure about how to do the process. |
 |
|
|
|
|
|