SQL - UPDATE data in table
Update in SQL is one of the operation in Data Management Language. In update we do updation of data already created or inserted into table. Update is really useful for doing changes in existing data without deleting and reinserting the data with changes.
Update - this should be done carefully otherwise it will create a problem like without filtering the required record change providing change that could be reflected for all the records.
Let see with an example,
Syntax:
UPDATE table_name SET column_name= required_data WHERE column_name= value;
WHERE clause is optional, it requires only when the data update pertaining to some records not all.
Example:
Database name dailyupdates and table name user there want to update user id 3 data last name as Smith
USE dailyupdates
GO
UPDATE user SET LAST_NAME='Smith' WHERE id=3
GO
Check whether it has updated to id =3 only and then give commit command the transactions would be saved permanently.
Delete operation in SQL
SQL - Structured Query Language is used to work on database to retrieve and load data. Delete offers database to delete the records in table. It does not touch the table structure.
Let's see the syntax of delete
Delete from table_name [where column_name=value]
-> Delete is keyword for delete operation
-> from is keyword in SQL
-> table_name, provide from which table name wants to delete
-> where is keyword in SQL to filter
-> column_name is.column name that is used for filter, it should be one the table column
-> value is column data that want to delete
Note: Where clause is optional and if not provided then all the records of the table will be deleted.
Example,
Delete from users Where user_id=123
If want to delete all the records from the table just remove the where clause and execute
Delete from users
*** Any queries on delete operation comment us ***
Comments
Post a Comment