Reputation: 29
On my database table stocks
, I have the columns:
stock_id
make
model
buy_rate
tax
other_charges
After inserting data into the above table, I have added a new column named sell_rate
which is at the moment NULL
.
sell_rate
using buy_rate
+ tax
+ other_charges
?Upvotes: 0
Views: 54
Reputation: 155
You can use update statement as other guys suggested for fill column in records which are already exist. for fill the column in the future automatically you should set the column as 'Computed Column' by Set:
Table Design -> Computed Column Specification -> Formula to : buy_rate + tax + other_charges
But you should be aware about some considerations like:
-Computed Columns have some restrictions for indexing (in some cases)
-You can't insert or update directly computed columns
Check this Article for more information.
Note: another ways are using update Trigger or defining a job which are useful in specific situations
Upvotes: 0
Reputation: 21
Hope this works
UPDATE stocks
SET sell_rate = (buy_rate + tax + other_charges)
Upvotes: 0
Reputation: 2729
UPDATE table_name
SET sell_rate=buy_rate+tax+othercharges;
This will update all the rows with appropriate values.
Upvotes: 0
Reputation: 186833
Try something like that:
UPDATE stocks
SET sell_rate = buy_rate + tax + other_charges
Upvotes: 1