Table of Contents
Introduction to Data Manipulation Language in SQL
Data manipulation language is used to retrieve information from the table and modify the data which is present in the table this language in SQL is widely used to retrieve data from multiple tables.
commands of DML in SQL.
- SELECT – retrieve data from the database
- INSERT – insert data into a table
- UPDATE – updates existing data within a table
- DELETE – deletes all records from a table, the space for the records remain.
With the help of these commands of DML, we can retrieve, modify, insert the data from the table.
Select Command
Select command in SQL is used to select the columns from the table to retrieve the rows from it.
Without a select clause, we cannot retrieve the rows from the table.
Syntax of Select Command:-
Select [Column_name]
From [table name]
Cndition_Clause [Condition column];
For example:-
Display first_name and salary from the employees’ table?
Query:-
Select first_name,salary
From employees;
Output:-
First_name Salary
Abel 24000
Rambo 12000
Here we use Select statement to select the columns first_name and last_name to retrieve the information.
Insert command
After creating a table by using DDL language the main task is ti full the data into the created table the DML insert command is used to insert a row in the table.
Syntax of Insert Command:-
Insert Into [Table_name] values (column_value1,column_value2);
For example:-
Name | Null | Type | |
STUDENT_ID | NOT NULL | NUMBER(10) | |
STUDENT_NAME | CHAR(20) | ||
BRANCH_ID | VARCHAR2(10) | ||
STUDENT_NO |
Widget not in any sidebars
This is the predefined table insert the row inside the table.
Query:-
Insert into students Values(101,'Abhishek','civil',123456);
Insert into students Values(102,'Sahil','mech',78912)
Output:-
STUDENT_ID STUDENT_NAME BRANCH_ID STUDENT_NO
101 Abhishek civil 123456
102 Sahil mech 78912
Update Command
The update command is used to change values that already exist in a table.
Name | Null | Type | |
STUDENT_ID | NOT NULL | NUMBER(10) | |
STUDENT_NAME | CHAR(20) | ||
BRANCH_ID | VARCHAR2(10) | ||
STUDENT_NO |
After adding some information if you want to update the records or change that time you have to use update command.
Syntax of update command:-
UPDATE table
SET column_name = value [column = value …]
[WHERE condition];
For example:-
Data in a table :-
STUDENT_ID | STUDENT_NAME | BRANCH_ID | STUDENT_NO |
101 | Abhishek | Civil | 123456 |
102 | Sahil | Mech | 78912 |
Update the branch_id=civil to branch_id=ctech ?
Update students
set branch_id='ctech'
where branch_id='civil';
Output:-
STUDENT_ID STUDENT_NAME BRANCH_ID STUDENT_NO
101 Abhishek ctech 123456
102 Sahil mech 78912
Widget not in any sidebars
Here we update the existing value in the table.
DELETE Command
Delete command is used to delete some specific rows followed by the condition which we pass in the where clause from the table.
Syntax of Delete command
Delete From table _name
where condition;
For example:
Data in a table:
STUDENT_ID | STUDENT_NAME | BRANCH_ID | STUDENT_NO |
101 | Abhishek | Civil | 123456 |
102 | Sahil | Mech | 78912 |
Delete the record who have a student_id 101. ?
SQL> Delete from Students
2 wherestudent_id =101;
Output:- 1 row deleted.
STUDENT_ID STUDENT_NAME BRANCH_ID STUDENT_NO
102 Sahil mech 78912