SQLTeam.com | Weblogs | Forums

CURSOR in stored procedure


#1

Hi.
I want to create a cursor in a stored procedure. What this procedure does is that:
-Adds the same column (PARENT_COLUMN as INT) to two tables (STUDENT, GRADE_EVENT), not all tables. The database I use is STUDENTDB.
Any help, please.
Thank you.


#2

This needs neither a cursor nor a stored procedure:

use STUDENTDB;
alter table STUDENT add PARENT_COLUMN int;
alter table GRADE_EVENT add PARENT_COLUMN int;

Even if you wrote a procedure, with or without a cursor, it would have to execute those 2 statements and can only run once, since column names must be unique within a table.


#3

Sounds like homework ... if your Prof is asking you to write a Cursor then ... my only advice is that good SQL coding will avoid cursors and use Set Based methods instead, so I suggest challenging what the benefit of a Cursor is in the general area being taught