If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Adding a column and updating the column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-08, 08:28
123apple 123apple is offline
Registered User
 
Join Date: Jul 2008
Posts: 1
Adding a column and updating the column

--------------------------------------------------------------------------------

I would like to add a new column to a table that takes the information from another column and subtracts 10% from that number. The following is what I have so far. I don't know how to complete the trigger statement to set the information from the other row. Additionally, I want to make the default value of the new column pListPrice -10%. Any ideas would be much appreciated! Thanks!

ALTER TABLE products ADD a_price DOUBLE DEFAULT (SELECT pListPrice *.9 FROM products);

CREATE TRIGGER t_products BEFORE UPDATE ON products FOR EACH ROW SET a_price = pListPrice*.9
Reply With Quote
  #2 (permalink)  
Old 07-14-08, 08:49
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You don't need to store something that is so easily calculable - just put the calc on your select queries
Code:
SELECT product_id
     , pListPrice
     , pListPrice * 0.9 As [a_price]
FROM   products
You can even create this as a view and job's a good'un!
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On