Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append to a existing record in SQL?

Can someone tell me how to append in SQL? I've going around all day trying to figure this out. This is what I have so far:

update table1 
set field1 = field1 + '123456' 
where field2 = '12'

Sorry, I forgot to mention that I'm updating more than one field in the statement.

like image 890
jorame Avatar asked Jun 10 '11 22:06

jorame


People also ask

How do you append a record in SQL?

We will use Append Query in SQL. For Implementing the Append Query in SQL Here First of all we will create Database and inside the we will create a table with some Record. For database creation there is query we will use in SQL Platform, like Mysql, oracle, etc.

How do you update an existing record in SQL?

The UPDATE command in SQL is used to modify or change the existing records in a table. If we want to update a particular value, we use the WHERE clause along with the UPDATE clause. If you do not use the WHERE clause, all the rows will be affected.

How do I add data to an existing table in SQL?

If you want to add data to your SQL table, then you can use the INSERT statement. Here is the basic syntax for adding rows to your SQL table: INSERT INTO table_name (column1, column2, column3,etc) VALUES (value1, value2, value3, etc); The second line of code is where you will add the values for the rows.


1 Answers

Your statement should work as long as field1 is not null or the data to be appended is not null.

Something like this could help in the case where field1 is null.

update table1 set field1 = ISNULL(field1, '') + '123456' where field2 = '12'
like image 136
bsexton Avatar answered Sep 26 '22 02:09

bsexton