I've recently discovered a flaw in one of my nightly stored procedures which causes it to crash. This procedure was written to give Patron constituencies based on existing associations. The problem is that it will sometimes try to give a constituency of that particular type to someone who already had that constituency except that it's now inactive. The procedure is therefore crashing on a violation of PRIMARY KEY constraint, as it tries to add a new record of that customer_no and constituency (which together make the primary key for TX_CONST_CUST).
Bottom line, and possibly dumb question, I'm wondering if there's really any reason to keep inactive records in a TX table, since it seems that a lot of them don't do that (e.g. TX_CUST_KEYWORD). And, if so, it would seem that I could either delete all inactive records (e.g. where end_dt <= getdate()) of that constituency before I add them, or update the start_dt and end_dt for preexisting records accordingly.
Ideas?
Thanks, Tessiturians.
Hi Matt,
The rationale for keeping those inactive records is to have some historical knowledge of the constituency (i.e. they were a board member until 2005). That said, you can safely delete them without causing any problems. You just lose the history.
The other option is to expand the logic in your job a bit and check for an inactive constituency and then removing the end date to reactivate it. It will really depend on whether the start and end dates matter to you for that particular constituency.
- Levi