Problem solve Get help with specific problems with your technologies, process and projects.

Trigger to update table with no foreign keys to original

I am trying to use a trigger on SQL Server 7.0. I have a table, employee, with attributes like cEmployeecode, vFirstname, vLastname, etc., and I also have a table called Positiontable with attributes cPositioncode, icurrentstrength, vdescription, etc. I intend on creating the trigger so that if any value is inserted in the employee table, the currentstrength should be updated and increased by one(icurrentstrength + 1). But the employee table has no primary key that is a foreign key in the position table, so how do I create the trigger to this effect?

While it is strongly recommended that you have a primary key on your employee table as well as a foreign key for your position table, you do not need it for a trigger. You should always have a primary key on a table, otherwise you have no ability to uniquely identify a row. If you have tables that relate to each other, you should also have a foreign key in order to ensure that you can not orphan data in those related tables.

If positiontable is not related at all to employee, then you can simply do this by the following:

 Update positiontable Set icurrentstrength = icurrentstrength + 1
That would, of course, increment every single row in positiontable when a row was inserted into employee.


For More Information

Dig Deeper on Microsoft SQL Server Installation

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.