I have a company table which has person_id(int) and a current_company(bit) fields. How can I create a trigger to ensure that the current_company bit set to 1 is unique for a person. I think the best way is to take the person_id (@person_id) from the row that is being inserted or updated, and then
set current_company = 0
where person_id = @person_id and current_company = 1
but I am unfamiliar with triggers and their syntax.
This table basically holds employment history, so there may be multiple companies for a given person_id, but only one of them can be the current company.
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.