ALTER (RENAME) in SQL (original) (raw)

Last Updated : 12 Jun, 2026

Renaming tables is a common structural change required during database maintenance or schema updates. SQL provides the ALTER TABLE command to rename tables without affecting existing data.

**Example: First create a sample Student table to demonstrate the ALTER command:

students-table

Student Table

**Query:

ALTER TABLE students
RENAME TO learners;

**Output:

Alter-table

Learners Table

Syntax

Here are the common syntax formats for using the ALTER TABLE command:

**1. Renaming a Table

ALTER TABLE table_name
RENAME TO new_table_name;

**2. Renaming a Column

ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name;

**3. Adding a New Column

ALTER TABLE table_name
ADD column_name datatype;

**4. Modifying a Column Data Type

ALTER TABLE table_name
MODIFY COLUMN column_name new_datatype;

Examples

Below are practical examples to help us understand how to use the ALTER command effectively in various scenarios. These examples include renaming tables or columns, adding new columns, orchanging columndata types. Consider the Student table below:

Screenshot-2026-02-06-141950

Student Table

Example 1: Rename a Column

Change the name of column name to FIRST_NAME in table Student. To change the column name of the existing table we have to use Column keyword before writing the existing column name to change.

**Query:

ALTER TABLE name RENAME Column name TO FIRST_NAME;

**Output:

Screenshot-2026-02-06-142259

Rename column

Example 2: Rename a Table

In this example, we want to rename the table from Student to Student_Details using the ALTER TABLE command, making the name more descriptive and relevant to its content.

**Query:

ALTER TABLE Student RENAME TO Student_Details;

**Output:

Screenshot-2026-02-06-142259

Student_Details Table

Example 3: Add a New Column

To add a new column to the existing table, we first need to select the table with ALTER TABLE command table_name and then we will write the name of the new column and its datatype with ADD column_name datatype. Let's have a look below to understand better.

**Query:

ALTER TABLE Student_Details ADD marks INT;

**Output:

Screenshot-2026-02-06-142729

Example 4: Modify a Column Data Type

In this example, the marks column is updated from INT to DECIMAL to store numeric values more precisely, allowing fractional marks and improving data accuracy.

**Query:

ALTER TABLE Student_Details
MODIFY COLUMN marks Decimal(5,2);

Additional ALTER Command Use Cases

The ALTER command can also be used for various other table modifications beyond renaming.

**1. Removing a Column: In some cases, we might need to remove a column. To do that, you can use the DROP COLUMN syntax:

ALTER TABLE Student_Details
DROP COLUMN marks;

This command deletes the marks column entirely from the table

**2. Changing a Column's Default Value: We can also modify a column’s default value using the SET DEFAULT clause:

ALTER TABLE Student_Details
ALTER COLUMN age SET DEFAULT 18;

**3. Renaming a Table or Column in Different Databases: Note that SQL syntax can vary across different database systems. Here’s how we would rename a table or column in MySQL, MariaDB and Oracle:

ALTER TABLE Student
CHANGE COLUMN old_column_name new_column_name datatype;

ALTER TABLE Student
RENAME COLUMN old_column_name TO new_column_name;