42

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.

Artic-M00n
  • 533
  • 2
  • 8
  • 15
  • 4
    `UPDATE` updates data stored in the row in the database table; `ALTER` is used to change the database table's **structure** - e.g. add a column, add or drop a constraint - it has nothing to do with the **contents** of the table (only its structure) – marc_s Jul 02 '12 at 11:50
  • 7
    How can anyone claim this is either not a real question or ambiguous? It's as simple and straightforward as they come: The OP wants to know what the difference is between ALTER and UPDATE, and he got a decent answer - thankfully, before it was closed for this non-reason – Malik A. Rumi Feb 05 '16 at 14:33

5 Answers5

62

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.

Joyce Babu
  • 19,602
  • 13
  • 62
  • 97
18

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.

Matzi
  • 13,770
  • 4
  • 33
  • 50
6

ALTER is used to change things like table structures or stored procs, otherwise known as DDL statements.

ALTER table MyTable 
ADD MyNewColumn VARCHAR(100)

OR

ALTER PROC dbo.MyStoredProc
Chris Gessler
  • 22,727
  • 7
  • 57
  • 83
1

Alter command is a data definition language Update command is a data manipulation language Alter example- table structure, table name, sp, functions Update example-change database in a row or column etc Alter command make changes in table structure. Update command make changes with inside the table Alter command is used to add, delete modify the attributes of the table in the database Update command is used to update existing record in a database

0

Let's see in simple words...

Alter command we use for the modify the structure of the database, table(add, drop, modify)and it falls under DDL.

Update command we use for the modify the rows(records) of the table using where condition and its fall under DML.