Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill a Column for Every Row in a Database

I just added a new column to a table which has over 1000 rows of data. I am wondering how I can update the new column with a piece of data for all of the rows in the database without having to manually do it.

What is the easiest way to accomplish this?

I am working with a MS SQL 2005 server. Thank you in advance for your advice.

like image 614
ThaKidd KG5ORD Avatar asked Dec 20 '10 17:12

ThaKidd KG5ORD


People also ask

How do I SUM all rows in a column in SQL?

If you need to add a group of numbers in your table you can use the SUM function in SQL. This is the basic syntax: SELECT SUM(column_name) FROM table_name; The SELECT statement in SQL tells the computer to get data from the table.

How do you fill data in a table in SQL?

Use INSERT to insert rows into a table. You can either specify every column value in parentheses after the VALUES keyword, or you can specify a comma-separated list of columns name before VALUES , and only specify those column values in the parentheses after.


2 Answers

Try this out.

UPDATE table_name SET column_name = value

This is given that the value you want to assign is a constant. Is that correct?

like image 178
Nick Vaccaro Avatar answered Oct 10 '22 08:10

Nick Vaccaro


UPDATE  mytable
SET     newcolumn = 'newvalue'
like image 23
Quassnoi Avatar answered Oct 10 '22 08:10

Quassnoi