UPDATE in SQL
We have to use UPDATE command to update the data in SQL.
Update all the rows in a table:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
Here we have given alias name as A for Employee, if we don't give alias we have to use the entire table name beside UPDATE command as shown below:
UPDATE Employee
SET FirstName = 'Akshar'
FROM
Employee
WHERE LastName = 'Anil'
Update only those rows which are satisfying specific condition:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
WHERE LastName = 'Anil'
We can also use joins in UPDATE statement:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
INNER JOIN Department D
ON A.DeptID = D.DeptID
WHERE
D.DeptName = 'HR'
Update all the rows in a table:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
Here we have given alias name as A for Employee, if we don't give alias we have to use the entire table name beside UPDATE command as shown below:
UPDATE Employee
SET FirstName = 'Akshar'
FROM
Employee
WHERE LastName = 'Anil'
Update only those rows which are satisfying specific condition:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
WHERE LastName = 'Anil'
We can also use joins in UPDATE statement:
UPDATE A
SET A.FirstName = 'Akshar'
FROM
Employee A
INNER JOIN Department D
ON A.DeptID = D.DeptID
WHERE
D.DeptName = 'HR'
Labels: SQL Basics, SQL Learning, sql script to update data in a table, Update in SQL, update query in sql
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home