DDL||DML Flashcards
What is used in DML ?
- INSERT
- UPDATE
- DELETE
Write a query where you need to insert 2 rows in EMP_Parth table
Empid EMP_NAME. SALARY
101 ANU. 3000
102 Mahi 4000
Insert into EMP_PARTH
(EMPID, EMP_NAME, SALARY)
values(‘101’, ‘ANU’, ‘3000’);
Insert into EMP_PARTH
(EMPID, EMP_NAME, SALARY)
values(‘102’, ‘Mahi’, ‘4000’);
Write a query to update the EMP_NAME ‘ANU’ to ‘TANNU’ from EMP_PARTH table where EMP_ID = 101
Try to get the syntax for update sql
Update EMP_PARTH
Set EMP_NAME = ‘TANNU’
where EMP_ID=101;
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, …, columnN = valueN
[WHERE condition];
What is Dev Env ?
Development where the developer develop the code and do unit testing
Write a query to concat first_name, middle_name, and last_name together and separate by ‘_’ between each column, take that column name as full_name from EMP_Parth table
Also write the query using pipe function
pipe and concat are the same thing but have different purposes. Pipe is more shorter queries but concat is used in more complex queries
Select concat(first_name,’ ‘,middle_name,’ ‘,last_name) AS full_name
from EMP_Parth;
Select first_name||’ ‘||Middle_name||’ ‘||last_name AS full_name
From EMP_Parth;
What is Substr and the syntax ?
Extracts a substring from a string (starting at any position)
Substr( column_name, start_position, number of characters)
Write a query to display employee_ID, first_name, last_name, salary where first_name starts with A from employees table
Select employee_ID, first_name, last_name, salary
from employees
Where SUBSTR(first_name, 1,1) = ‘A’;
Write a query to display employee_ID, first_name, last_name, salary where first_name ends with ‘a’ from employees table
Select employee_ID, first_name, last_name, salary
from employees
Where SUBSTR(first_name, -1,1) = ‘A’;
Write a query to display employee_ID, first_name, last_name, salary where second letter of first_name is ‘r’ from employees table
Select employee_ID, first_name, last_name, salary
from employees
where SUBSTR( first_name, 2,1) = ‘r’;
What is INSTR and the syntax ?
It is the search string of a substring
INSTR( column_name, search_character, start_position, occurrence)
Write a query to display employee_ID, first_name, last_name from employees table where character ‘ a’ will be after position 2
Select employee_ID, first_name, last_name
from employees
Where INSTR(first_name, ‘a’,1)>2;
Write a query to display employee_ID, first_name, last_name from employees table where character ‘r’ will be after 3 position
Select employee_ID, first_name, last_name
from employees
Where INSTR(first_name, ‘r’,1)>3;
What is Length, replace, and translate ? what are the syntax
Check your notes in pictures
What is Decode and what is the syntax ?
The SQL DECODE function is a database function used for conditional value replacement in a query result. It is primarily used in Oracle Database and a few other database systems. DECODE allows you to compare a value to a set of possible values and return a corresponding result when a match is found.
Decode( column_name, search1, result1, search2, result2, default_result)
What is the syntax for left outer Join ?
Select Column_name
From table_name1 LEFT OUTER JOIN table_name2
On table_column1 = table_column2
Where condition;
What is the syntax for right outer join ?
Select column_name
From table1_name RIGHT OUTER JOIN table2_name
ON table1_column = table2_column
Where condition;
What is the syntax for Inner Join ?
Select column_name
From Table1_name Inner Join table2_name
On table1_column = table2_column
Where condition;
What is the syntax for full outer join ?
Select column_name
From table1_name Full outer join Table2_name
On table1_column = table2_column
Where condition ;
Query to display Employee_id, First_name, Manager_id, Salary, Department_id, Department_name, all records from employees table and matching records from departments tables whose salary is smaller than 5000.
Select e.employee_ID, e.First_name, e.Manager_ID, e.Salary, e.Department_ID, d.Department_name
From Employees e Left outer Join departments d
On e.department_ID = d.department_ID
Where salary < 5000;
Query to display Employee_id, First_name, Manager_id, Salary, Department_id, Department_name, matching records from employees tables and all records from departments tables whose salary is smaller than 5000.
Select e.employee_ID, e.First_name, e.Manager_ID, e.Salary, e.Department_ID, d.Department_Name From employees e right outer join department d
On e.department_ID = d.department_ID
Where Salary < 5000;
Query to display Employee_id, First_name, Salary, Department_id, Department_name, only matching records from employees and departments tables whose salary is greater than 10000
Select e.Employee_id, e.First_name, e.Salary, e.department_id, d.department_name From Employees e Inner Join Departments d On e .department_id = d. department_id Where Salary >10000;