I've got a table with a column, lets call it table_column
that is currently null
for all rows of the table. I'd like to insert the value "test"
into that column for all rows. Can someone give me the SQL for this?
I've tried INSERT INTO table (table_column) VALUES ("test");
but that only populates that last row. How do I do all of the rows at once?
This question is related to
mysql
sql
sql-update
sql-insert
UPDATE `table` SET table_column='test';
To update the content of existing rows use the UPDATE
statement:
UPDATE table_name SET table_column = 'test';
This is because in relational database terminology, what you want to do is not called "inserting", but "UPDATING" - you are updating an existing row's field from one value (NULL in your case) to "test"
UPDATE your_table SET table_column = "test"
WHERE table_column = NULL
You don't need the second line if you want to update 100% of rows.
What you're actually doing is adding rows. To update the content of existing rows use the UPDATE statement:
UPDATE table SET table_column = 'test';
To create a new empty column and fill it with the same value (here 100) for every row (in Toad for Oracle):
ALTER TABLE my_table ADD new_column INT;
UPDATE my_table SET new_column = 100;
The SQL you need is:
Update table set table_column = "test";
The SQL you posted creates a new row rather than updating existing rows.
Source: Stackoverflow.com