2.DML ( Data Manipulation Language)
This language commands are used to change or manipulate data in database tables.
Insert :-Inserting a new row into a table. There are two methods to insert rows into a table:
🡆Implicit Method :-Inserting all values for all columns into a table (without specifying any column).
🡆Syntax:-Insert [into] <TableName> Values (Value1, Value2, Value3, …);
Ex:-Create table student (STID int, SName Nvarchar(40), Sfee decimal(6,2), SAge tinyint);
Ex:-Insert into student values (101, ‘SAI’, 2500, 21) OR Insert student values (102, ‘JAMES’, 4500, 23)
🡆Explicit Method :-Inserting values for required columns only (with left any column in the table).
Syntax:-Insert [INTO] <TableName> (<Required Column Names>) Values (103, ‘ALLEN’);
🡆How to Insert Multiple rows into a table
Syntax for Implicit:-Insert [INTO] <TableName> Values (Row1 values), (Row2 values), …;
Ex:-Insert into student values (104, ‘Scott’, 800, 22), (105, ‘Ward’, 1000, 25);
🡆Syntax for Explicit :-Insert [INTO] <TableName> (<Required Column Names>) Values (<Row1 values>), (<Row2 values>);
Ex: Insert student (STID) values (106), (107), (108)
Update:- Updating all rows data in a table at a time or a specific row data in a table by using “Where” condition.
🡆Syntax:- Update <TableName>
SET <ColumnName1> = <Value1>, <ColumnName2> = <Value2>
[Where Condition];
Ex: Write a query to update employee job as HR, salary as 14,000 whose employee number is 7788.
Update Emp
Set Job = ‘HR’, Salary = 14000
Where EmpNo = 7788;
🡆Ex: Write a query to update all employee commission as 500.
Update Emp
Set Comm = 500;
Delete;-Deleting all rows from the table at a time or a specific row from the table by using “Where” clause condition.
🡆Syntax:Delete from <TableName> [Where Condition];
🡆Ex: Write a query to delete employee from the table who are working in the job as clerk.
Delete from Emp Where Job = ‘clerk’;
🡆Ex: Write a query to delete all emp details from the table.
Delete from Emp;