Question:
How do I insert this data to an existing SQL field?
G Master
2010-11-03 16:45:36 UTC
Hello,

I'm trying to insert data to existing fields, and currently it's adding another row of information and inserting the values there.

What i'd like for it to do is insert data into the existing rows

Here's my current code:

SELECT * FROM customers
WHERE customers_id = 2;
INSERT INTO customers (customers_petName,customers_petPhoto)
VALUES ("Stella","photo.png")

Please help.Thanks
Three answers:
david
2010-11-03 16:47:54 UTC
Try this:



UPDATE Customers SET customers_petName = "Stella", customers_petPhoto = "photo.png" WHERE customers_id = 2
John S
2010-11-05 03:31:41 UTC
If you INSERT the data into customers you will be duplicating the data (the insert creates new rows).



INSERT INTO customers

(customers_petName,customers_petPhoto)

SELECT customers_petName,customers_petPhoto

FROM customers WHERE customers_id = 2;'



To change existing data use the UPDATE statement.



UPDATE customers SET customers_petName="Stella",customers_petPhoto="photo.png";



Note that will only work if you just want the name of the file conatining the customer's pet's photo. In Oracle you can have a BLOB column which can be a pointer to an external file (such as a photo).



For more on SQL see our Oracle tutorials http://www.asktheoracle.net/oracle-tutorials.html
TheMadProfessor
2010-11-04 14:54:41 UTC
INSERT does exactly that - inserts a new row of data into the table. To change an existing row, use UPDATE instead.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...