DML stands for Data Manipulation Language. DML statements are used to manipulate data. The SQL statements that are in the DML category are INSERT, UPDATE and DELETE.
INSERT - Insert statement is used to insert data into SQL Server Table.
UPDATE - Update statement is used to update/change the existing data into SQL Server Table.
DELETE - Delete statement is used to delete data from SQL Server Table.
Now we will see Insert, Update and Delete one by one.
We have a Table
and it's name is STUDENT
. There is some columns in the table like StudentID, Name, FatherName, Email, MobileNumber, Address. Now, we write a SQL query to insert data in STUDENT table.
In general terms, we keep a column in the Table as Primary Key that column is used to uniquely identify the records in table. We will discuss about Primary Key in another post.
insert into student (StudentID,Name,FatherName,Email,MobileNumber,Address) values (1,'Rakesh Kumar','Upendra Singh','firstname.lastname@example.org','9015214789','Sec 7 Rohini, New Delhi')
Update: SQL Update statement is used to change the existing data with the reference of its unique ID. Means, we need a UNIQUE ID to update a particular record. In this example that I am going to show you StudentID is a Unique ID.
Update student set Name='Mahesh Kumar', FatherName='Sundar Singh', Emailemail@example.com', MobileNumber='8541236987', Address='Adarsh Nagar, New Delhi' where StudentID=1
In above example SET is SQL keyword that is used to assign a value to columns of table or variables.
Delete: As the word delete, every one aware of this word delete means remove. Same here in SQL Server Delete is also used to remove or delete the existing record from SQL Table. If you want to delete only one record from SQL Table then we have to know its Unique Identifier value. And you can delete that record. In this example StudentID is a Unique ID and we will use StudentID to delete a record from SQL Table.
Delete from Student where StudentID=1