Table of contents
1.
Introduction🤔
2.
🎯ALTER Command✅
3.
🎯UPDATE Command✅
4.
ALTER vs UPDATE command📋
5.
Frequently Asked Questions
5.1.
What is SQL?
5.2.
What is a database made up of?
5.3.
How are actions performed on the database?
5.4.
What are the different subsets of SQL?
5.5.
What are Tables?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

ALTER vs UPDATE Command

Author Sanchit Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction🤔

Sometimes, when dealing with tables in SQL, one might wonder how to manipulate the table's structure by adding, deleting or modifying columns or updating the existing data.

alter vs update command

We will find answers to all such questions in this article on the ALTER vs UPDATE command.

Are you ready❓

Also read, Coalesce in SQL and Tcl Commands in SQL

🎯ALTER Command✅

alter command

The ALTER TABLE statement or alter command is a data definition language(DDL) command used to modify, add or delete columns in the existing table. It is used to change the definition of the table, or we can say it is used to alter the table's structure.


📌ALTER TABLE - ADD COLUMN

Use the given below syntax to add a column in a table➡

ALTER TABLE the_table_name ADD the_column_name datatype;


⚙️For example - the following SQL statement adds an "Address" column to the "Users" table➡

ALTER TABLE Users ADD Address varchar(255);


📌ALTER TABLE - DROP COLUMN

Use the given below syntax to delete a column in a table➡

ALTER TABLE the_table_name DROP COLUMN the_column_name;


⚙️For example - the following SQL statement deletes the "Address" column from the "Users" table➡

ALTER TABLE Users DROP COLUMN Address;


Note⚠️ - some database systems do not allow deleting a column that has a CHECK constraint. Also, SQL Server does not allow deleting the column that has a PRIMARY KEY or a FOREIGN KEY constraint.


📌ALTER TABLE - ALTER COLUMN

Use the given below syntax to change the data type of a column in a table➡

ALTER TABLE the_table_name ALTER COLUMN the_column_name datatype;


⚙️For example - the following SQL statement changes the data type of the "DOB" column in the "Persons" table➡

ALTER TABLE Persons ALTER COLUMN DOB year;


Now let us see the UPDATE command before moving on to the differences in ALTER vs UPDATE command.🏄

🎯UPDATE Command✅

update command

The UPDATE TABLE statement or update command is a Data manipulation language (DML) command used to manipulate the data of any existing column inside the table. It does not affect the definition of the table.


Use the given below syntax to update the data of any existing column in a table➡

UPDATE table_name
SET column_name1 = value1, column_name2 = value2..., column_nameN = valueN
WHERE <condition>;


⚙️For example - the following SQL statement updates the data of the "name" column and "last_name" column according to a condition in the "user" table➡

UPDATE user SET name ='Sanchit', last_name ='Kumar' WHERE id = '22';


So far, we have understood the ALTER command and the UPDATE command separately. Now let us see the difference between ALTER vs UPDATE command.🏄‍♀️

ALTER vs UPDATE command📋

ALTER Command

UPDATE Command

It is a Data Definition Language(DDL). It is a Data Manipulation Language (DML).
ALTER Command changes the definition of the table. UPDATE command operates on the data level.
This command is used to add, delete, and modify the attributes of the tables in a database. It updates the existing records in a database.
This command initialises the value of all the tuples as NULL. This command sets fixed values in a tuple.
It changes the structure of the table. It changes the data inside the table.

We hope you have understood ALTER vs UPDATE command.

You can also study Difference Between Rank and Dense Rank here.

Frequently Asked Questions

What is SQL?

SQL is a standard language to access and manipulate databases, and it stands for the structured query language.

What is a database made up of?

A database contains one or more tables. The table contains records with data and is identified by a name.

How are actions performed on the database?

The actions are performed on a database with the help of SQL statements.

What are the different subsets of SQL?

Data definition language (DDL), data manipulation language(DML) and data control language(DCL).

What are Tables?

A table is a collection of data components organised in columns(attributes) and rows(records) in a relational database.

Conclusion

In this article, we discussed ALTER vs UPDATE command. We learnt how to manipulate the table's structure and update the existing data.

We believe this article on the ALTER vs UPDATE command was helpful. You can refer to other similar articles as well - 


Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enrol in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

You can start practicing SQL Problems here.

Happy Learning Ninja! 🥷

Live masterclass