Insights Technical Hub How to change existing columns in an SQL table

How to change existing columns in an SQL table

Introduction:

Tables in SQL (Structured Query Language) databases may at times need to be modified. There are two approaches to do so.

Requirements:

An SQL development environment.

Procedure:

Once a connection to an SQL server is acquired and a database’s table is selected for modification, you can change its columns using two different approaches. First, you can change a column’s attributes using:

alter table tableName modify columnName columnAttributes;

Or, if you would like to change the column name as well, you may use:

alter table tableName change previousColumnName newColumnName columnAttributes;

You can use the second approach (using the keyword change) to only modify the attributes by repeating the pre-existing column name twice. This is instead of including a replacement column name after the previous column name.

Let's make your job easier

Sign up to get insightful content