This is one of the tables in my database. Constraints omitted for clarity.
CREATE TABLE [Person].[Person]
(
[ID] INT NOT NULL IDENTITY,
[Forename] VARCHAR(16) NOT NULL,
[Surname] VARCHAR(32) NOT NULL,
[Gender] CHAR(1) NOT NULL DEFAULT 'U',
[DateOfBirth] DATETIME NULL,
[HobbiesAndInterests] VARCHAR(256) NULL,
[AdditionalInformation] VARCHAR(512) NULL,
[LocalCentreID] INT NOT NULL DEFAULT 0,
[EmergencyContactID] INT NULL,
)
The problem I have involves the date of birth field. If a value is provided, I need to run a check against the date. If a value is not provided, the check does not need to run.
I basically need to check if the person is 18 or older based on the date of birth. If a date of birth isn't provided, then there's no need for it to be checked.
I've thought a few different ways I can address this:
The first is obviously to place a check constraint on the date of birth field but I think this fails if the date is null.
Another option is to use a scalar UDF inside the check constraint.
The final option I've thought of is to use an AFTER INSERT/UPDATE trigger to check the date and rollback if the date is invalid.
I've spoken to a colleague and he says technically I'm checking a business rule in the database, so this check should be pushed off to the application.
Is there a 'right' way to approach this problem or is it basically what the developer thinks is best?