for example i created an employees table with columns named emp_id,emp_name,emp_job etc. and i wanted to add a manager number column ie. 'mgr_no', so i made this column with the alter statement with default null values.
Now my question is i already have 50 entries in the table and i want to enter 50 entries for mgr_no column which at the moment is empty or null,do i have to use the update command 50 times to fill the column, or is there a way to add values without running the update command 50 times.
PS: iam using oracle 11g as it is bounded by my teacher.
It depends on whether you want to update all (or many) rows to have the same new mgr_no
value, or to 50 different values.
If you need 50 different values, then yes, you have to run 50 UPDATE
s. That's pretty normal though and not a problem.
Otherwise, if you can "group" the new values: The UPDATE
statement by default already updates all rows that match the filter. So just writing UPDATE employees SET mgr_no = 123
will set all 50 of your employees to have manager 123. You actually have to use a WHERE
to limit this behavior. If you want to set the manager to 123 only for employees with job accounting
, you'd use UPDATE employees SET mgr_no = 123 WHERE emp_job = 'accounting'
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.