Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


s.joseph

590 posts

Ultimate Geek

Trusted

#58556 14-Mar-2010 16:52
Send private message

how would i go about chaging the value of something ive added in a database in sql

eg. originally i inserted this.

Insert into Fruit values
(1, 'Apple', '$4.99'),
(2, 'Orange','$3.99'),

what script would i use to change oranges to 2.99?
is it update?

its for my uni submission but i cant experiment on sql because my computer has flipped out.

Create new topic
jeffreyh
54 posts

Master Geek


  #307114 14-Mar-2010 16:59
Send private message

update fruit set <whatever the $ value column is called>='$2.99'
where <whatever you have called the id column>=2 



s.joseph

590 posts

Ultimate Geek

Trusted

  #307115 14-Mar-2010 17:03
Send private message

thank you!

rvangelder
352 posts

Ultimate Geek


  #307162 14-Mar-2010 19:14
Send private message

you're storing the amounts as a string? really?
you should store numeric data as a numeric data type. do the formatting later, in the application or report.

assuming you've changed the amount datatype to a number:
update fruit set amount = 2.99 where fruit_id = 2;

otherwise as string:
update fruit set amount = '$2.99' where fruit_id = 2;



nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #307226 14-Mar-2010 22:39
Send private message

rvangelder: you're storing the amounts as a string? really?
you should store numeric data as a numeric data type. do the formatting later, in the application or report.


+1

Definitely start good habits now, plenty of reasons why to store data correctly - uses less space, better performance, easier to write queries etc.



ReaperSA
3 posts

Wannabe Geek


  #307528 15-Mar-2010 20:31
Send private message

PS The insert will fail...

You need to specify destination columns in your insert query i.e.
Insert into Fruit(IDField,FruitName,Price) values
(1, 'Apple', '$4.99'),
(2, 'Orange','$3.99'),

Also rather use an autonumber field for the first column as this will allow you to index your datatables making queries faster.

Just my humble opinion. :)
 

rvangelder
352 posts

Ultimate Geek


  #307577 15-Mar-2010 22:11
Send private message

I think it's good practise to name the columns too, but his SQL won't fail for that reason.
Named columns are optional (depending on the database).
http://download.oracle.com/docs/cd/B14156_01/doc/B13812/html/sqcmd.htm#BABGFGDA

A few tidy ups for those inserts
1 insert statement per row of data:
insert into fruit (fruit_id, name, amount) values (1, 'Apple', 4.99);
insert into fruit (fruit_id, name, amount) values (2, 'Orange', 3.99);

If you're developing an application, bind parameters wherever you can.
Not only will it increase performance by saving the database from re-parsing your SQL and calculating a query path for every line, it can protect your application from a security problem called "sql injection". http://xkcd.com/327/. You'll immediately notice vulnerable websites - those that can't handle an apostrophe in a text field.

Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.