DML or Data Manipulation Language is used to manipulate the data that is present in database table.It basically includes 5 commands:
1.SELECT:
2.UPDATE
3.INSERT
4.DELETE
5.RENAME
We will discuss about each of the commands in depth:
1.INSERT Command:
In previous article, we toured through different Data Definition languages in which we basically build a table and define its structure.Now , inside the constructed table, we have to insert data and manipulate it when needed. Insert command is used to insert data into the table.
Syntax: INSERT INTO table_name values(‘value1′,’value2’,…..);
Example: Suppose we have the following table:
Table name: Student
Column names: Name Roll number
We will start filling the table as follows:
Insert into Student values(‘Sneha’,12);
Insert into Student values(‘Rebicca’,’14’);
If we run the above two queries, the newly created table becomes:
Column attributes: Name Roll number
Row1: Sneha 12
Row2: Rebicca 14
2.Update command:
Update command is used to update certain value in table explicitly.
Syntax: Update table_name
Set column_name=value
Where some condition.
Example:
Suppose in the above table, we want to update the roll number values to 7 for Sneha.
Update student
Set Roll number=7
Where name=’sneha’
3.Select Command:
Select command is used to retrieve the desired values from database table.
Syntax:
Select value1,value2,….from table_name;
Examples:
1.Suppose we want to extract all the informations from the above table:
Select * from Student;
We will get:
Sneha 12
Rebicca 14
2.Suppose we want to extract information related to Sneha.
Here we will have to specify a where clause.
Select * from Student where name =’Sneha’
We will get : Sneha 12
3. Suppose we want to extract only one column say roll number.
Select roll_number from Student where name =’Sneha’;
We will get : 12
4.Delete command:
Delete command is used to remove any record from the database table.Where clause can be specified if we want to delete some specific record.
Syntax:
Delete from table where condition;
Example:
Suppose from the above table, we want to delete all the information relate to Sneha.
Delete from Student where name=’sneha’