Difference between ALTER and UPDATE Command in SQL
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 table ALTER TABLE tableName ADD columnName columnDefinition; // drop a column from the existing table ALTER TABLE tableName DROP COLUMN columnName; // rename a column in the existing table ALTER TABLE tableName RENAME COLUMN olderName TO newName; // modify the datatype of an already existing column in the table ALTER TABLE table_name ALTER 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 update UPDATE tableName // which columns have to update SET column1 = value1, column2 = value2, ...,columnN=valueN. // which row you have to update WHERE condition
Note : Without WHERE clause, all records in the table will be updated.
Difference Between ALTER and UPDATE Command in SQL:
SR.NO | ALTER Command | UPDATE Command |
---|---|---|
1 | ALTER command is Data Definition Language (DDL). | UPDATE Command is a Data Manipulation Language (DML). |
2 | Alter command will perform the action on structure level and not on the data level. | Update command will perform on the data level. |
3 | ALTER 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. |
4 | ALTER Command by default initializes values of all the tuple as NULL. | UPDATE Command sets specified values in the command to the tuples. |
5 | This command make changes with table structure. | This command makes changes with data inside the table. |
6 | It works on the attributes of a relation. | It works on the attribute of a particular tuple in a table. |
7 | Example : 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 |
Syntax with Example Syntax: UPDATE tableName SET column1 = value1, column2 = value2, ..,columnN = valueN. WHERE condition Example: UPDATE Students |
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.
Please Login to comment...