tags:

views:

33

answers:

2

How to add a column to the table:

create table table1 (id integer primary key, field1 text)

? The column would be field2 text and the value for existing rows in this column should be value.

+1  A: 

That would be the SQL syntax:

ALTER TABLE table_name ADD column_name datatype

In your case, you'd be looking at:

alter table table1 add field2 text
update table1 set field2 = 'value'
paxdiablo
+1  A: 

For MySQL:

ALTER TABLE table1 ADD field2 text;
UPDATE table1 SET field2='value';
gahooa
Why not to use: alter table table 1 add field2 text default 'value'
Bogdan Gusiev
Because he did not specify that he always wanted the value to be 'value'. He just said "existing rows"...
gahooa