Oracle

Adding a Column and Inserting Values

Using the ADD clause with the alter table command allows a user to add a new column to a table. The new column must be defined by a column name and datataype. The default values can also be assigned. The new column will be added at the end of the existing table- it will be the last column. The syntax for the ALTER TABLE command with the ADD clause is as below.

ALTER TABLE tablename ADD (columnname datatype [Default value] ,—);

Adding a Column and Inserting Values

Adding a Column and Inserting Values

Modifying Existing Rows

Insert command can not be used in this case to add values into this new column. Because the INSERT INTO command can be used only to add new values to a table, it can not modify existing data. UPDATE command is used to alter existing table data. The Syntax of the update command is :

UPDATE tablename SET Columnname = newa-value, – - -[where condition] ;

The optional WHERE clause identifies the exact row or the set of rows to be changed by the UPDATE (identifies the table) command. If the where clause is not specified in the SET clause (used to identify the column name) is updated for all records contained in the table.

Be the first to comment - What do you think?  Posted by admin - January 23, 2010 at 8:04 pm

Categories: Oracle, SQL Server   Tags: ,