MainMenu

Home Core Java Overview Maven Tutorials

Sunday, 15 January 2017

Alter Keyword with example

Use of Alter Keyword

Syntax : Alter Table Table_name ADD column_name datatype Example : Consider the following table Table: Salary

Emp_idEmp_nameEmp_regEmp_salary
01chandanE_0125000
02adhirajE_0230000
03raghuE_0335000
04raghunathE_0436000
05AlaxE_0540000
and it is required to add new column(city) in table then we will use alter keyword Query : Alter table Salary ADD column city varchar(50) Result:
Emp_idEmp_nameEmp_regEmp_salarycity
01chandanE_0125000Null
02adhirajE_0230000Null
03raghuE_0335000Null
04raghunathE_0436000Null
05AlaxE_0540000Null

Query to update column datatype :

In Mysql : ALTER TABLE table_name MODIFY COLUMN column_name datatype In sql : ALTER TABLE table_name ALTER COLUMN column_name datatype

Query to drop a column in Table

Syntax : ALTER TABLE tablename DROP COLUMN columnname Example : ALTER TABLE tablename DROP COLUMN city Now column city will be droped from table salary

Tag :Alter keyword with example, use of alter keyword in SQL

No comments:

Post a Comment