Javatpoint Logo
Javatpoint Logo

SQL MODIFY COLUMN

In this SQL article, we will discuss how to modify the column of the table in Structured Query Language.

What is MODIFY COLUMN Statement?

In many situations, you may require to modify the existing columns or fields of the existing table. So, SQL provides the MODIFY keyword with ALTER TABLE command to overcome this problem.

The MODIFY keyword modifies the size, datatype, and constraints of the existing field of the SQL table.

Syntax of MODIFY Column statement

This ALTER syntax allows us to modify the single field of the existing table.

If you want to modify more than one new field of the same SQL table in a single statement, then you have to use the following syntax:

Example of MODIFY Column statement in SQL

If you want to learn how to modify the column of the table, you have to create a new table.

The following statement creates the Teacher_Details table in SQL:

The below INSERT queries insert the records of Employees with Grades and Remarks in the Employee_Grade table:

The following SELECT statement displays the inserted records of the above Employee_Grade table:


Employee_ID First_Name Last_Name First_City Second_City New_City Attendance_Remarks Work_Remarks Grade
10 Ramesh Sharma Lucknow Aurangabad Ghaziabad 88 95 A2
02 Yadu Sharma Aurangabad Ghaziabad Ghaziabad 95 82 A1
07 Vijay Ramna Noida Ghaziabad Lucknow 91 95 A1
04 Bhanu Rangopalr Ghaziabad Noida Lucknow 85 82 NULL
11 Harry Roy Noida Kanpur Ghaziabad 95 97 A1
16 Akash Ramna Ghaziabad Meerut Aurangabad 95 90 B1
19 Ram Ramna Lucknow Ghaziabad Aurangabad 89 95 NULL

Query 1: The following ALTER query modifies the Grade column of the above table:

This query makes the Grade column as 'NOT NULL' in the table. Now, this column will not store NULL value.

Query 2: The following ALTER query modifies the New_City column of the above Employee_Grade table:

This query changes the size of the new city column of the table.

Query 3: The following ALTER query modifies the multiple columns of the above table:

This query changes the size of the first name, last name, and the first city of the Employee_grade table.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA