Difference between ALTER and UPDATE Command in SQL - GeeksforGeeks (2024)

Last Updated : 11 Apr, 2023

Improve

1. ALTER Command:

ALTER SQL command is a DDL (Data Definition Language) statement. ALTER is used to update the structure of the table in the database (like add, delete, modify the attributes of the tables in the database).

Syntax:

// add a column to the existing tableALTER TABLE tableNameADD columnName columnDefinition; // drop a column from the existing tableALTER TABLE tableNameDROP COLUMN columnName;// rename a column in the existing tableALTER TABLE tableNameRENAME COLUMN olderName TO newName;// modify the datatype of an already existing column in the tableALTER TABLE table_nameALTER COLUMN column_name column_type;

2. UPDATE Command:

UPDATE SQL command is a DML (Data manipulation Language) statement. It is used to manipulate the data of any existing column. But can’t be change the table’s definition.

Syntax:

// table name that has to updateUPDATE tableName// which columns have to updateSET column1 = value1, column2 = value2, ...,columnN=valueN.// which row you have to updateWHERE condition

Note : Without WHERE clause, all records in the table will be updated.

Difference Between ALTER and UPDATE Command in SQL:

SR.NOALTER CommandUPDATE Command
1ALTER command is Data Definition Language (DDL).UPDATE Command is a Data Manipulation Language (DML).
2Alter command will perform the action on structure level and not on the data level.Update command will perform on the data level.
3ALTER Command is used to add, delete, modify the attributes of the relations (tables) in the database.UPDATE Command is used to update existing records in a database.
4ALTER Command by default initializes values of all the tuple as NULL.UPDATE Command sets specified values in the command to the tuples.
5This command make changes with table structure.This command makes changes with data inside the table.
6It works on the attributes of a relation.It works on the attribute of a particular tuple in a table.
7Example : Table structure, Table Name, SP, functions etc.Example : Change data in the table in rows or in column etc.
8

Syntax with Example

Syntax:

ALTER TABLE tableName

DROP COLUMN columnName;

Example:

ALTER TABLE Students
DROP COLUMN Address;

Syntax with Example

Syntax:

UPDATE tableName

SET column1 = value1, column2 = value2, ..,columnN = valueN.

WHERE condition

Example:

UPDATE Students
SET Name = ‘SAM’, City= ‘GREEN’
WHERE StudentID = 10;

The Alter statement is is used when we needs to change something in table or modify the table whereas the Update statement is used when user wants to modify something in data which is stored in the table. We can say that Alter works with table structure of the table and Update works with data within the table.


Like Article

Suggest improvement

Share your thoughts in the comments

Please Login to comment...

Difference between ALTER and UPDATE Command in SQL - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6698

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.