Creating Clever Constituencies

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.

Parents
  • Hi Matt,

    If you are updating the start date anyways (or don't care about the old start dates), I don't see any reason why you wouldn't just delete those records and add the new ones. I think this is a pretty common practice.
    Having accidentally deleted all constituencies before, I'd just say to be sure to test that thoroughly first. Thankfully for me I was in my Test system at the time.

    Cheers! 



    [edited by: Ryan Rowell at 12:06 PM (GMT -6) on 6 Mar 2014]
Reply
  • Hi Matt,

    If you are updating the start date anyways (or don't care about the old start dates), I don't see any reason why you wouldn't just delete those records and add the new ones. I think this is a pretty common practice.
    Having accidentally deleted all constituencies before, I'd just say to be sure to test that thoroughly first. Thankfully for me I was in my Test system at the time.

    Cheers! 



    [edited by: Ryan Rowell at 12:06 PM (GMT -6) on 6 Mar 2014]
Children
No Data