Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger can't insert dup key

Status
Not open for further replies.

Greg25

Technical User
May 30, 2001
159
US
Here’s A trigger I created

Create Trigger TRG_status_change ON Order_entry
For Update
As
If update (Last_cost_center_code)
Begin
Insert Job_workflow (Cost_center_code, row_id)
Select Last_Cost_center_code, row_id
From inserted
End

I think it will work if I only knew how I could make the primary key unique or to select a number that has not been used yet

Thanks Greg
 
I think i figured this out but still need to enter the time and date the cost center is changed to and from cost center
 
Greg, I'm kind of reading between the lines, but it sounds like your problem is trying to identify a Pk in job_workflow.

I don't normally declare PKs for my audit trail tables, but that's just a personal failing of mine. If you want to, add a column for DateChanged and insert into it the value GetDate(), then make your PK include DateChanged. That way, multiple changes to a single row will still allow you a unique key. Robert Bradley
Sr. DBA, some big company
cheap prints and oil paintings:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top