0

I have two tables department and employee.

In the department table I have three columsn: DEP_ID, NAME, HIKEINPERCENT

In the employee table I have four columns: EMP_ID, DEP_ID, EMP_NAME, SALARY

Now if I update the HIKEINPERCENT in the department table, it should update the SALARY of the employees in the employee table by using CURSOR in SQL Server.

PLS GUIDE WITH EXPLANATION..

4
  • 5
    WHY with a cursor!?!?!? Commented Nov 2, 2012 at 12:40
  • 3
    @marc_s: cursors and all caps in questions often go together. Commented Nov 2, 2012 at 12:41
  • Avoid cursors in tsql if possible. In plsql they are good, but in tsql they are just a slow mess. Commented Nov 2, 2012 at 13:12
  • @SoonDead - Any stats on that? I would have assumed cursors are to be avoided in plsql too. One of the issues with cursors in TSQL is simply that cursors is an imperative approach whereas a declarative set based approach allows the query as a whole to be optimised. Commented Nov 2, 2012 at 13:19

1 Answer 1

1

Don't use a cursor. If you update the department HIKEINPERCENT field, you should have the DEP_ID to do so, something like :

update department set HIKEINPERCENT = @someNewValue where DEP_ID = @DepartementId

Then, you should update the SALARY in the employee table using something like :

update employee set SALARY = @SomeCrazyNewValue where DEP_ID = @DepartmentId

If this does not help you, please provide more specific info in the OP.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.