Update syntax for a SQL Query

Update query in SQL RDBMS database

Update
Update is used for updating the column data in the table of RDBMS database. Update query is DML statement.
It is used to update the exiting column value of any table in RDBMS if you have permission of update to that table.

Note:
1. Without WHERE clause in statement it will update all column value of a table. So, use of update is very carefully.
2. You have to give grant privileges to user on table on which you want to give update privileges.
Grant update on table_name to user;

Syntax

-- For single column
Update table_name set column_name = value1 where column_name2 = value2;

--For multiple column
update table_name set col1 = val1, col2 = val2 where col_name = value;

--For update all rows without WHERE clause
update table_name set col1 =val1 ;

Example
support want to update the first name and last name of the employee having employee id = 2

Update employees set first_name = 'Rakesh', last_name = 'Sharma'  where emp_id = 2;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.