Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Alter and Update SQL

I am busy studying MySQL and I understand that update is used to update a record or row in a table. So what does alter do that is so different? Seems like they are the same.

Thanks, any help will be appreciated.

like image 272
Artic-M00n Avatar asked Jul 02 '12 11:07

Artic-M00n


People also ask

What is the difference between ALTER and rename in SQL?

Summary. The alter command is used when we want to modify a database or any object contained in the database. The drop command is used to delete databases from MySQL server or objects within a database. The rename command is used to change the name of a table to a new table name.

Is ALTER and modify same?

Update is used to modify/update already existing data. If the data is not found it will give an error. Alter is used to add, delete, or modify columns in existing table it is also used to add or drop constrains.


2 Answers

ALTER is a DDL (Data Definition Language) statement. Whereas UPDATE is a DML (Data Manipulation Language) statement. ALTER is used to update the structure of the table (add/remove field/index etc). Whereas UPDATE is used to update data.

like image 184
Joyce Babu Avatar answered Oct 29 '22 22:10

Joyce Babu


The ALTER changes the table in the database, you can add or remove columns, etc. But it does not change data (except in the dropped or added columns of course).

While the UPDATE changes the rows in the table, and leaves the table unchanged.

like image 33
Matzi Avatar answered Oct 29 '22 21:10

Matzi