SQL Alter Command


Prev Tutorial Next Tutorial

SQL Alter Command

Alter Command is used to modify the structure of the table. Using this command you can perform four different operations. This command contains four sub commands that is;

  • Alter modify
  • Alter add
  • Alter rename
  • Alter drop

Alter modify

Using this command you can increase or decrease the size of data type and also you can change the data type from old data type to new data type.

Syntax

	
ALTER TABLE table_name MODIFY 
(
column 1 datatype(size),
column 2 datatype(size),
.........
);

Example

	
ALTER TABLE Employee MODIFY 
(
emp_name varchar(30),
);

Alter add

This command is used to add a new column in the table. Using this command you can add more than one column to the existing.

Syntax

	
ALTER TABLE table_name ADD 
(
column 1 datatype(size),
column 2 datatype(size),
.........
);

Example

	
ALTER TABLE Employee ADD 
(
emp_age number(5),
);

Note: You can not add the new column at required position in the table.

Alter rename

This command is used to change the column name from old column name to new column name.

Syntax

	
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;

Example

	
ALTER TABLE Employee RENAME salary to employee_salary;

Note: You can not change more than one column name at a time.

Alter drop

This command is used to remove the column from existing table.

Syntax

	
ALTER TABLE table_name DROP column_name;

Example

	
ALTER TABLE Employee DROP emp_name;

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements