Home » SQL

SQL Query to alter column size

In this article, we are going to learn about the property of column and then we will alter the pre-defined size of column.
Submitted by Manu Jemini, on March 14, 2018

The Columns can have multiple properties. These properties define just about everything the value of that column can have. Now, the data type of a column can be of a type which has upper limit to it. For example, type varchar has an upper limit, which tells us that how many characters the field can have.

Now the problem arises when we have set the upper limit and wants to change it. To solve it, use the ALTER keyword and tells it which column or field you want to change. This same like changing the name or type of the column.

You should always define the properties clearly during the creation of table because once the database increases, it will be difficult to keep track of everything.

Table (employee) having three fields and four data in it,

    Id		Name		Address

    100		Aman		Mumbai
    200		Arun		Pune
    300		Karan		Delhi
    400		Aman		Mumbai

As always we have our employee table with three column and four data rows in it and now we need to modify one of our column’s pre-defined size, suppose the column we need to alter names and then we can just take the column name and create a alter table query with modify column and give it a new size.

Query:

ALTER TABLE employee 
MODIFY COLUMN 'name' VARCHAR(100) DEFAULT NULL;

Output

SQL Query to alter column size



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.