there is already some columns added in my table starsin.. i want to add a column address in my table starsin by using a query..
A:
If this is mysql, you can do ALTER TABLE stasin ADD COLUMN <columnname> <type> <options>
webdestroya
2010-05-13 04:09:17
+1
A:
In standard SQL, you want the alter table X add column Y ...
command.
If you then want to populate the column for all existing rows, it's a simple matter of working out the query and: update X set Y = ...
.
Here's an example session which shows you the alter table add column
in action (for DB2):
> CREATE TABLE XYZ (F1 INTEGER);
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
> INSERT INTO XYZ VALUES (1);
DSNE615I NUMBER OF ROWS AFFECTED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
> INSERT INTO XYZ VALUES (2);
DSNE615I NUMBER OF ROWS AFFECTED IS 1
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
> SELECT * FROM XYZ;
F1
--
1
2
DSNE610I NUMBER OF ROWS DISPLAYED IS 2
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 100
> ALTER TABLE XYZ ADD COLUMN F2 INTEGER;
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
> UPDATE XYZ SET F2 = F1 + 7;
DSNE615I NUMBER OF ROWS AFFECTED IS 2
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
> SELECT * FROM XYZ;
F1 F2
-- --
1 8
2 9
DSNE610I NUMBER OF ROWS DISPLAYED IS 2
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 100
paxdiablo
2010-05-13 04:10:34
do i have to drop a table afrer altering it?
Abid
2010-05-13 04:13:11
...not unless you want to get rid of it
Matti Virkkunen
2010-05-13 04:15:04
Good one, Matti :-) No, altering doesn't create a new table, it modifies the current table.
paxdiablo
2010-05-13 04:20:12
A:
See here
Code:
ALTER TABLE Sales
ADD UnitPrice MONEY;
Output: The command(s) completed successfully. Explanation: This example adds a single field to the 'Sales' table by specifying the new field name and data type. Language(s): MS SQL Server
David Basarab
2010-05-13 04:10:56
A:
alter table <tablename> add(<coloumn name> <datatype>);
normal sql query to add a coloumn... in oracle it will work....
navinbecse
2010-05-13 09:20:03