SQL Add Column | Add Column in SQL - sql - sql tutorial - learn sql




 add column sql
  • A table definition modifies by altering, adding, or dropping columns & constraints, reassigning and rebuilding partitions, or disabling or enabling constraints and triggers.
  • The statement ALTER TABLE, which is also used to add & drop various constraints on an existing table.
  • Sometimes we wish to add a column to a table.
  • This can be achieved in SQL.
  • we specify that we want to alter the table structure via the ALTER TABLE command, followed by the ADD command to tell the RDBMS that we want to add a column.

The SQL syntax for ALTER TABLE Add Column is,

ALTER TABLE "table_name" 
ADD "column_name" "Data Type";

For example, assuming our starting point is the Employee table created in the CREATE TABLE section:

 add column in sql

Table Employee

Column Name Data Type
First_Name char(50)
Last_Name char(50)
Address char(50)
City char(50)
Country char(25)
Birth_Date datetime
  • Our goal is to add or insert a column called "Gender":
 alter table add column
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

MySQL:

ALTER TABLE Employee ADD Gender char(1);
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Oracle:

ALTER TABLE Employee ADD Gender char(1);

SQL Server:

ALTER TABLE Employee ADD Gender char(1);
  • The resulting table structure is:

Table Employee

Column Name Data Type
First_Name char(50)
Last_Name char(50)
Address char(50)
City char(50)
Country char(25)
Birth_Date datetime
Gender char(1)

Note: The new column Gender becomes the last column in the Employee table.

  • Similarly, it is also possible to add multiple columns. For example, if we want to add a column called "Emp_id" & another column called "Salary", we will type the following:
 drop column in sql
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

MySQL:

ALTER TABLE Employee ADD (Emp_id char(30), Salary char(20) );
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Oracle:

ALTER TABLE Employee ADD (Emp_id char(30), Salary char(20) );

SQL Server:

ALTER TABLE Employee ADD (Emp_id char(30), Salary char(20) );
  • The table now becomes:

Table Employee

Column Name Data Type
First_Name char(50)
Last_Name char(50)
Address char(50)
City char(50)
Country char(25)
Birth_Date datetime
Gender char(1)
Emp_id char(30)
Salary char(20)

This tutorial provides more the basic needs and informations on sql tutorial , pl sql tutorial , mysql tutorial , sql server , sqlcode , sql queries , sql , sql formatter , sql join , w3schools sql , oracle tutorial , mysql , pl sql , learn sql , sql tutorial for beginners , sql server tutorial , sql query tutorial , oracle sql tutorial , t sql tutorial , ms sql tutorial , database tutorial , sql tutorial point , oracle pl sql tutorial , oracle database tutorial , oracle tutorial for beginners , ms sql server tutorial , sql tutorial pdf

Related Searches to SQL Add Column | Add Column in SQL