Home » SQL

SQL query to change column datatype

SQL ALTER TABLE Example: Here, we are going to learn how to change the column data types in SQL?
Submitted by Abhishek Goel, on April 26, 2020

Datatype of the column in SQL can be changed using the ALTER TABLE command. It can also be used to ADD, DELETE or MODIFY columns in already existing tables. It can also be used to ADD or DROP constraints in the SQL database.

Here we are going to only talk about changing the datatype of the column.

For doing the task the following syntax is used,

    ALTER TABLE table_name
    MODIFY COLUMN column_name datatype;

Let's understand the above-mentioned concept with the help of example.

Let us consider the table "People".


Here we are going to change the datatype for birth_year from int to year datatype.

SQL Query:

MODIFY COLUMN birth_year year;

After the commitment of this program code, the column birth_year is now of type year and can only store birth_year in the two or four-digit format.

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.