Home > Mobile >  Add new column SQL
Add new column SQL

Time:05-14

I created a table in Oracle with sales and cost (both numbers). Now, I want to alter it and add a new column called profit. is there an easier way to insert the profit information to the exisiting values i have?

CodePudding user response:

Are you looking for a generated column?

ALTER TABLE t1 ADD COLUMN c2 int GENERATED ALWAYS AS (sales-cost) STORED;

Syntax example only. The actual data type and options would differ depending on your goals and data types.

CodePudding user response:

Add column in table

Syntax

To add a column in a table, the ALTER TABLE syntax in SQL is:

*ALTER TABLE table_name

ADD column_name column_definition;*

Example Let's look at a SQL ALTER TABLE example that adds a column.

For example:

*ALTER TABLE supplier

ADD supplier_name char(50);*

  • Related