Skip to content
Advertisement

Passing parameters for a constraint function

I have the following table that joins driver and truck tables in order to assign trucks to drivers. I need to constraint entries that belong to the same driver on the same day, and DO NOT include the same truck code.

It was suggested to create a boolean function to pass along dateval, truckval and driverval, and returns the following.

I have tried creating a function returning a bit datatype, but I honestly lack knowledge on user created functions, how would I go about passing the parameters for the function?

Is there an easier approach to the whole situation?

Advertisement

Answer

You clearly have two different entities — but they are related. You have something like an “assignment” where a driver has a truck for one or more days. Then you have something like a “trip” where a driver uses the truck (what you are currently calling an “assignment”).

So, I would model this as:

Note that there is only one row per driver and per date. Voila! Only one truck.

You can then add as many trips for a driver that you like, but for a given driver, they all have the same truck.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement