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 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:-
From [table name]
Cndition_Clause [Condition column];
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.
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);
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
The update command is used to change values that already exist in a table.
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:-
SET column_name = value [column = value …]
Data in a table :-
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
Here we update the existing value in the table.
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
Data in a table:
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