The Wayback Machine - https://web.archive.org/web/20241003063658/https://www.geeksforgeeks.org/difference-between-alter-and-update-command-in-sql/
Open In App

Difference between ALTER and UPDATE Command in SQL

Last Updated : 11 Apr, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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
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.  

 



Similar Reads

SQL Query to Drop Unique Key Constraints Using ALTER Command
Here, we see how to drop unique constraints using alter command. ALTER is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table. Syntax : ALTER TABLE table_name DROP CONSTRAINT unique_constraint; For instance, consider the below table 'Employee'. Create a Table: C
2 min read
SQL Query to Add Unique key Constraints Using ALTER Command
Here we will see how to add unique key constraint to a column(s) of a MS SQL Server's database with the help of a SQL query using ALTER clause. For the demonstration purpose, we will be creating a demo table in a database called "geeks". Creating the Database : Use the below SQL statement to create a database called geeks: CREATE DATABASE geeks; Us
2 min read
SQL Query to Drop Foreign Key Constraint Using ALTER Command
A foreign key is included in the structure of a table, to connect multiple tables by referring to the primary key of another table. Sometimes, you might want to remove the primary key constraint from a table for performance issues or other requirements. A foreign key constraint can be removed from a table using the ALTER TABLE command and DROP CONS
3 min read
SQL Query to Add Foreign Key Constraints Using ALTER Command
In relational databases, a Foreign Key Constraint is a fundamental concept that defines a relationship between two tables. It ensures that the value of one or more columns in a child table corresponds to the value in a primary key or unique key in a parent table. In this article, we will look into how we can add a foreign key constraint using the A
3 min read
Create, Alter and Drop schema in MS SQL Server
Schema management in MS SQL Server involves creating, altering, and dropping database schema elements such as tables, views, stored procedures, and indexes. It ensures that the database structure is optimized for data storage and retrieval. In this article, we will be discussing schema and how to create, alter, and drop the schema. What is Schema?A
4 min read
Alter login in SQL Server
Alter login statements can be used to changes the properties of a SQL Server login account. Syntax: ALTER LOGIN loginname; GO Enable a disabled login - Syntax : ALTER LOGIN loginname ENABLE; Example - ALTER LOGIN geeks ENABLE; Change password of a login Syntax : ALTER LOGIN geeks WITH PASSWORD = 'newpassword'; Example - ALTER LOGIN geeks WITH PASSW
1 min read
How to Alter Multiple Columns at Once in SQL Server?
In SQL, sometimes we need to write a single query to update the values of all columns in a table. We will use the UPDATE keyword to achieve this. For this, we use a specific kind of query shown in the below demonstration. For this article, we will be using the Microsoft SQL Server as our database and Select keyword. Step 1: Create a Database. For t
3 min read
SQL ALTER COLUMN
In today's data-driven world, successful organizations require the ability to process and manipulate data effectively as part of their business foundation. Structured Query Language (SQL) is a powerful tool that enables users to manipulate relational databases. Within SQL, there is an entity where data can be stored, retrieved, and manipulated. Thi
4 min read
SQL ALTER TABLE
SQL ALTER TABLE command can add, delete, or modify columns of an existing table. This article discusses the SQL ALTER TABLE statement with examples and syntax. ALTER TABLE STATEMENTThe ALTER TABLE statement in SQL is used to add, remove, or modify columns in an existing table. The ALTER TABLE statement is also used to add and remove various constra
2 min read
SQL Query to Alter Column Size in MySQL
To Alter the Column size in MySQL use the ALTER TABLE statement with MODIFY Clause. The ALTER TABLE statement allows users to add, delete, or modify columns in an existing table in MySQL. SyntaxSyntax to Alter column size in MySQL is: ALTER TABLE table_nameMODIFY column_namevarchar(new_length); MySQL Alter Column Size in ExamplesLet us look at some
2 min read
ALTER SCHEMA in SQL Server
The SQL Server ALTER SCHEMA statement is used to transfer an object (table, view, or function) from one schema to another schema in the same database. The ALTER SCHEMA statement is used to transfer an object from a schema to another schema in the same database. SyntaxALTER SCHEMA target_schema_name TRANSFER [ object_type :: ] object_name;Parameters
2 min read
ALTER (RENAME) in SQL
Sometimes we may want to rename our table to give it a more relevant name. For this purpose, we can use ALTER TABLE to rename the name of the table. SQL ALTER TABLE is a command used to modify the structure of an existing table in a database. Here we will discuss Alter Command in SQL in detail. Alter in SQLHere we are discussing the syntax of Alter
2 min read
How to Alter a Column from Null to Not Null in SQL Server
In SQL Server, columns are defined with specific constraints, one of which is the nullability of the column whether or not it can hold NULL values. As a database evolves, this setting may need to be changed particularly to ensure that certain data fields are always populated. Altering a column from NULL to NOT NULL is a common task when you want to
4 min read
How to Update Multiple Columns in Single Update Statement in SQL?
In this article, we will see, how to update multiple columns in a single statement in SQL. We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required. UPDATE for Multiple ColumnsSyntax: U
3 min read
Difference between Deferred update and Immediate update
1. Deferred Update: It is a technique for the maintenance of the transaction log files of the DBMS. It is also called NO-UNDO/REDO technique. It is used for the recovery of transaction failures that occur due to power, memory, or OS failures. Whenever any transaction is executed, the updates are not made immediately to the database. They are first
4 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Difference Between java.sql.Time, java.sql.Timestamp and java.sql.Date in Java
Across the software projects, we are using java.sql.Time, java.sql.Timestamp and java.sql.Date in many instances. Whenever the java application interacts with the database, we should use these instead of java.util.Date. The reason is JDBC i.e. java database connectivity uses these to identify SQL Date and Timestamp. Here let us see the differences
7 min read
BULK INSERT in SQL Server(T-SQL command)
BULK INSERT in SQL Server(T-SQL command): In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server and the way it is more useful and more convenient to perform such kind of operations. Let's discuss it one by one.  ConditionSometimes there is a scenario when we have to perform bulk insert data from .cs
3 min read
How to add a foreign key using ALTER in MySQL
In this article, we will discuss the overview of foreign keys and will discuss how to add a foreign key using ALTER in MySQL step by step. Let's discuss it one by one. Foreign key : If an attribute is a primary key in one table but was not used as a primary key in another table then the attribute which is not a primary key in the other table is cal
3 min read
update conflicts with concurrent update
In this article, we will discuss the overview of transaction, deadlock and will focus on update conflicts with the concurrent update and understand with the help of an example. Let's discuss it one by one. Transaction :A transaction is a logical unit of work that can have one or more SQL statements. A transaction ends when either you commit it or r
3 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
SQL vs NO SQL vs NEW SQL
SQL stands for Structured Query Language. Which is based on relational algebra and schema is fixed in this which means data is stored in the form of columns and tables. SQL follows ACID properties which means Atomicity, Consistency, Isolation, and Durability are maintained. There are three types of languages present in SQL : Data Definition Languag
2 min read
SQL | Difference between functions and stored procedures in PL/SQL
Prerequisite: Procedures in PL/SQLFunctions in PL/SQL.Difference between functions and stored procedures in PL/SQL Differences between Stored procedures(SP) and Functions(User-defined functions (UDF)): 1. SP may or may not return a value but UDF must return a value. The return statement of the function returns control to the calling program and ret
3 min read
Difference between T-SQL and PL-SQL
1. Transact SQL (T-SQL) : T-SQL is an abbreviation for Transact Structure Query Language. It is a product by Microsoft and is an extension of SQL Language which is used to interact with relational databases. It is considered to perform best with Microsoft SQL servers. T-SQL statements are used to perform the transactions to the databases. T-SQL has
3 min read
Difference Between Azure SQL Database and Azure SQL Managed Instances
Azure is a cloud platform which is used for services like virtual computing, storage networking etc. It provides with solutions that include Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS). Both, Azure SQL Database and Azure SQL Managed Instances supports automatic backup and have built-in license
3 min read
Difference between SQL and T-SQL
SQL (Structured Query Language) is the standard language for managing and manipulating relational databases, enabling operations like querying, updating, and deleting data. T-SQL (Transact-SQL), an extension of SQL developed by Microsoft, adds advanced features and procedural capabilities specifically for SQL Server. In this article, We will learn
4 min read
Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
In this article, we will be learning about how to do basic database operations using JDBC (Java Database Connectivity) API in Java programming language. These basic operations are INSERT, SELECT, UPDATE, and DELETE statements in SQL language. Although the target database system is Oracle Database, the same techniques can be applied to other databas
6 min read
SQL | UPDATE with JOIN
SQL UPDATE JOIN could be used to update one table using another table and join condition. Syntax - UPDATE tablename INNER JOIN tablename ON tablename.columnname = tablename.columnname SET tablenmae.columnnmae = tablenmae.columnname; Use multiple tables in SQL UPDATE with JOIN statement. Let us assume we have two tables - Geeks1 and Geeks2. To check
2 min read
Update Action in MS SQL Server
Referential Actions allow a user to either update or delete a column from the parent table. If a column is removed from the parent table, it is removed from the child table immediately. Syntax : foreign key (foreign-key_constraint) references parent_table (parentkey_column) ON Update Action Consider two tables - Student (Parent Table) and Marks (Ch
2 min read
Update Date Field in SQL Server
The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using the UPDATE statements as per our requirement. With this article, we will learn how to Update the Date Field in SQL Server. In this article, we will be making use of the Microsoft SQL Server as o
2 min read
Article Tags :