SQL BASIC STATEMENTS
Clause/Statement Definition Syntax Example Query
The SELECT statement is used to specify
SELECT which columns or expressions to retrieve SELECT column1, column2, ... SELECT emp_id, name, salary
from the database. FROM table_name; FROM employees;
The FROM clause is used to specify the
FROM SELECT columns SELECT emp_id, name
table(s) from which to retrieve the data. FROM table_name; FROM employees;
The WHERE clause filters records and
SELECT columns SELECT emp_id, name, salary
WHERE allows you to specify conditions for FROM table_name FROM employees WHERE salary >
selecting rows. WHERE condition; 50000;
The GROUP BY clause groups rows that SELECT columns,
SELECT department, AVG(salary)
GROUP BY have the same values into summary rows, AGGREGATE_FUNCTION(column)
FROM employees GROUP BY
often used with aggregate functions. FROM table_name
department;
GROUP BY column;
The HAVING clause filters groups created
SELECT columns, SELECT department, AVG(salary)
by the GROUP BY clause based on
HAVING AGGREGATE_FUNCTION(column) FROM employees
conditions, similar to WHERE, but applied FROM table_name GROUP BY department
to groups. GROUP BY column HAVING condition; HAVING AVG(salary) > 60000;
The ORDER BY clause is used to sort the SELECT department, AVG(salary)
FROM employees
result set by one or more columns in SELECT columns
ORDER BY WHERE salary > 50000
ascending (ASC) or descending (DESC) FROM table_name
GROUP BY department
order. ORDER BY column ASC
HAVING AVG(salary) > 60000
ORDER BY AVG(salary) DESC;
The CREATE statement is used to define a
CREATE TABLE employees (emp_id
CREATE new table, view, index, or database in the CREATE TABLE table_name (column1
INT, name VARCHAR(100), salary
system. datatype, column2 datatype, ...);
DECIMAL(10, 2));
The INSERT statement is used to add new INSERT INTO employees (emp_id,
INSERT INSERT INTO table_name (column1,
records to a table. name, salary) VALUES (101, 'John
column2, ...) VALUES (value1, value2, ...);
Doe', 60000);
The UPDATE statement is used to modify
UPDATE table_name SET column1 = UPDATE employees SET salary =
UPDATE existing records in a table based on value1, column2 = value2 65000
specified conditions. WHERE condition; WHERE emp_id = 101;
The DELETE statement is used to remove
DELETE existing records from a table based on DELETE FROM table_name DELETE FROM employees
specified conditions. WHERE condition; WHERE emp_id = 101;
The TRUNCATE statement removes all rows
from a table but does not remove the table
TRUNCATE TRUNCATE TABLE table_name; TRUNCATE TABLE employees;
itself. It is faster than DELETE and cannot
be rolled back in most cases.
The DROP statement is used to remove a
DROP table, view, or other database objects from DROP TABLE table_name; DROP TABLE employees;
the system entirely.
ALTER
Operation Definition Syntax Example Query
The ADD COLUMN operation is
ADD
used to add a new column to an ALTER TABLE table_name ALTER TABLE employees
COLUMN ADD column_name datatype; ADD age INT;
existing table.
The MODIFY COLUMN operation
MODIFY is used to change the data type,
ALTER TABLE table_name ALTER TABLE employees
COLUMN size, or other properties of an MODIFY column_name datatype; MODIFY salary DECIMAL(12, 2);
existing column.
The RENAME COLUMN operation
RENAME ALTER TABLE table_name ALTER TABLE employees
is used to rename an existing RENAME COLUMN old_column_name RENAME COLUMN salary
COLUMN
column in a table. TO new_column_name; TO annual_salary;
The DROP COLUMN operation is
DROP
used to remove a column from an ALTER TABLE table_name ALTER TABLE employees
COLUMN DROP COLUMN column_name; DROP COLUMN age;
existing table.
RENAME The RENAME TABLE operation is
ALTER TABLE old_table_name ALTER TABLE employees
TABLE used to rename an existing table. RENAME TO new_table_name; RENAME TO staff;
UNION, UNION ALL, MINUS
Operation Definition Syntax Example Query
SELECT columns SELECT emp_id, name
FROM table1 FROM employees
Combines results of two queries and
UNION removes duplicates.
UNION UNION
SELECT columns SELECT emp_id, name
FROM table2; FROM contractors;
SELECT columns SELECT emp_id, name
FROM table1 FROM employees
UNION Combines results of two queries and
UNION ALL UNION ALL
ALL retains all records including duplicates.
SELECT columns SELECT emp_id, name
FROM table2; FROM contractors;
SELECT columns SELECT emp_id, name
Returns only rows from the first table or FROM table1 FROM employees
MINUS query that are not in the second table or MINUS MINUS
query. SELECT columns SELECT emp_id, name
FROM table2; FROM contractors;
AGGRIGATE FUNCTIONS
Function Definition Purpose Syntax Example Query
Returns the number of rows (or non- To determine how many
COUNT() NULL values) in a column or result records meet certain COUNT(column_name) SELECT COUNT(emp_id)
set. criteria. FROM employees;
Calculates the total of all values in a To get the total of numeric
SUM() SUM(column_name) SELECT SUM(salary)
numeric column. values (e.g., total sales). FROM employees;
Returns the smallest (minimum) To find the lowest value in a
MIN() MIN(column_name) SELECT MIN(salary)
value in a column. dataset. FROM employees;
Returns the largest (maximum) value To find the highest value in
MAX() MAX(column_name) SELECT MAX(salary)
in a column. a dataset. FROM employees;
Returns the average (mean) of To calculate the average
AVG() AVG(column_name) SELECT AVG(salary)
numeric values in a column. value. FROM employees;
String Functions
Function Definition Syntax Example Query (Oracle SQL)
Returns ASCII value of the first
ASCII() ASCII(string) SELECT ASCII('A') FROM dual;
character of a string.
Returns the character corresponding to
CHR() CHR(ascii_code) SELECT CHR(65) FROM dual;
the given ASCII code.
SELECT CONCAT('Hello', 'World')
CONCAT() Concatenates two strings. CONCAT(string1, string2)
FROM dual;
Concatenates two strings using
` ` (pipe)
pipe operator.
SELECT INITCAP('prasanna') FROM
INITCAP() Converts string to Initial Capital letters. INITCAP(string)
dual;
INSTR(string, substring [, SELECT INSTR('Prasanna', 'a', 1, 2)
INSTR() Finds position of a substring in a string.
start_position [, occurrence]]) FROM dual;
Returns length (number of characters) of SELECT LENGTH('Prasanna') FROM
LENGTH() LENGTH(string)
a string. dual;
SELECT LOWER('PRASANNA')
LOWER() Converts string to lowercase. LOWER(string)
FROM dual;
SELECT UPPER('prasanna') FROM
UPPER() Converts string to uppercase. UPPER(string)
dual;
Pads the left side of a string with a SELECT LPAD('25', 5, '0') FROM
LPAD() LPAD(string, total_length [, pad_char])
character. dual;
Pads the right side of a string with a SELECT RPAD('25', 5, '*') FROM
RPAD() RPAD(string, total_length [, pad_char])
character. dual;
SELECT LTRIM('---Hello', '-') FROM
LTRIM() Removes leading spaces or characters. LTRIM(string [, trim_chars])
dual;
SELECT RTRIM('Hello---', '-') FROM
RTRIM() Removes trailing spaces or characters. RTRIM(string [, trim_chars])
dual;
Removes leading and trailing
TRIM() `TRIM([[LEADING TRAILING
characters.
Replaces occurrences of a substring with REPLACE(string, search_str [, SELECT REPLACE('banana', 'a', 'x')
REPLACE()
another. replace_str]) FROM dual;
SUBSTR(string, start_position [, SELECT SUBSTR('Prasanna', 1, 4)
SUBSTR() Extracts a substring from a string.
length]) FROM dual;
JOIN
Join Type Definition Syntax Example (Oracle) Use Case Example
SELECT * Get records with
Returns only the matching rows from both
INNER JOIN FROM A matching id in both
tables. INNER JOIN B tables.
ON A.id = B.id;
Returns all rows from the left table, and SELECT *
LEFT OUTER JOIN Show all A records even if
matched rows from right table (NULL if no FROM A
(or LEFT JOIN) LEFT OUTER JOIN B no match in B.
match).
ON A.id = B.id;
RIGHT OUTER SELECT *
Returns all rows from the right table, and Show all B records even if
JOIN (or RIGHT FROM A
matched rows from left table. RIGHT OUTER JOIN B no match in A.
JOIN)
ON A.id = B.id;
SELECT * Combine all data from
Returns all rows when there is a match in
FULL OUTER JOIN FROM A both tables, including
either left or right table. FULL OUTER JOIN B NULLs.
ON A.id = B.id;
Returns Cartesian product (each row of A SELECT * Use for all combinations
CROSS JOIN FROM A
joins with all rows of B). (e.g., size × color).
CROSS JOIN B;
SELECT A.name, B.name
A table joins with itself, useful for Find manager-employee
SELF JOIN FROM emp A
hierarchical or related data. JOIN emp B relationships.
ON A.emp_id = B.emp_id;
Automatically joins tables on columns with SELECT * Quick join if both tables
NATURAL JOIN FROM A
same name and data type. share column(s) by name.
NATURAL JOIN B;
Date Datatype
Function Definition Syntax Example Query (Oracle SQL)
Converts a string to a date,
TO_DATE() using the specified date TO_DATE(string, format) SELECT TO_DATE('2025-04-18', 'YYYY-MM-DD')
format. FROM dual;
Adds or subtracts a
ADD_MONTHS() specified number of ADD_MONTHS(date, number_of_months) SELECT ADD_MONTHS(SYSDATE, 2)
months to a date. FROM dual;
Extracts a specified part
EXTRACT() (like year, month, day, etc.) EXTRACT(part FROM date) SELECT EXTRACT(YEAR FROM SYSDATE)
from a date or timestamp. FROM dual;
Converts a string to a
SELECT TO_TIMESTAMP('2025-04-18 14:30:00',
TO_TIMESTAMP() timestamp, using a TO_TIMESTAMP(string, format) 'YYYY-MM-DD HH24:MI:SS')
specified format. FROM dual;
Truncates a date or
TRUNC() timestamp to a specific unit TRUNC(date [, format]) SELECT TRUNC(SYSDATE, 'MM')
(e.g., year, month, day). FROM dual;
Returns the last day of the
LAST_DAY() LAST_DAY(date) SELECT LAST_DAY(SYSDATE)
month for a given date. FROM dual;
Returns the next specified
NEXT_DAY() weekday after the given NEXT_DAY(date, 'day_name') SELECT NEXT_DAY(SYSDATE, 'SUNDAY')
date. FROM dual;
Rounds a date or
timestamp to the nearest
ROUND() ROUND(date [, format]) SELECT ROUND(SYSDATE, 'YYYY')
specified unit (e.g., month, FROM dual;
day).
Returns the current date
CURRENT_DATE (without time) of the system CURRENT_DATE SELECT CURRENT_DATE
in the session's time zone. FROM dual;
Returns the current date
and time (with timezone) of
CURRENT_TIMESTAMP CURRENT_TIMESTAMP SELECT CURRENT_TIMESTAMP
the system in the session's FROM dual;
time zone.
Returns the current date
SYSDATE and time (in the database SYSDATE SELECT SYSDATE
server's time zone). FROM dual;
Returns the current
SYS_TIMESTAMP timestamp (with time zone) SYS_TIMESTAMP SELECT SYS_TIMESTAMP
of the system. FROM dual;
Types of Constraints in Oracle SQL
Constraint Type Definition Enforcement Example
Ensures that each record in a Combines NOT NULL and UNIQUE
CREATE TABLE employee (emp_id INT
PRIMARY KEY table has a unique identifier and constraints, ensuring that the column(s)
PRIMARY KEY, name VARCHAR2(50));
does not allow NULL values. have unique values and no NULL.
Ensures the value in a column
Maintains referential integrity between two CREATE TABLE orders (order_id INT, emp_id
matches a value in the
FOREIGN KEY tables, ensuring that the child table's INT, FOREIGN KEY (emp_id) REFERENCES
referenced column of another
column matches the parent table's column. employee(emp_id));
table (parent table).
Guarantees that no two rows have the same
Ensures all values in a column CREATE TABLE student (student_id INT
UNIQUE value for the specified column, but NULL
are unique. UNIQUE, name VARCHAR2(50));
values are allowed.
Ensures that a column cannot Prevents the insertion of NULL values into a CREATE TABLE student (student_id INT
NOT NULL
contain NULL values. column. NOT NULL, name VARCHAR2(50));
Ensures that a column's values Allows defining custom conditions for a
CREATE TABLE product (product_id INT,
CHECK meet a specific condition or column's values (like value ranges, or
price DECIMAL CHECK (price > 0));
constraint. specific values).
Sets a default value for a column Automatically inserts a predefined value CREATE TABLE product (product_id INT,
DEFAULT when no value is provided during into a column if no value is specified by the name VARCHAR2(50), quantity INT
insertion. user. DEFAULT 10);
While not a "data integrity" constraint, it is
Creates an index on a column to CREATE INDEX emp_index ON
INDEX used to speed up queries by indexing
improve search performance. employee(emp_id);
frequently used columns.
Analytical Functions
Function Definition Syntax Example Query
Assigns a rank to each
RANK() SELECT emp_name, salary, RANK() OVER
row within a partition, RANK() OVER (PARTITION BY col
(ORDER BY salary DESC) AS rank_sal FROM
(e.g., 1,2,2,4) allowing gaps if there are ORDER BY col2)
employees;
ties.
DENSE_RANK() Similar to RANK(), but no SELECT emp_name, salary, DENSE_RANK()
DENSE_RANK() OVER (PARTITION BY
gaps between ranks OVER (ORDER BY salary DESC) AS
(e.g., 1,2,2,3) col ORDER BY col2)
(dense). dense_rank_sal FROM employees;
ROW_NUMBER() Assigns a unique row ROW_NUMBER() OVER (PARTITION
SELECT emp_name, salary, ROW_NUMBER()
number to each row in OVER (ORDER BY salary DESC) AS row_num
(e.g., 1,2,3,4) BY col ORDER BY col2)
the result set. FROM employees;
Returns the value from SELECT emp_name, salary, LEAD(salary) OVER
LEAD(col, [offset], [default]) OVER
LEAD() the next row in the table (ORDER BY emp_name) AS next_salary FROM
(PARTITION BY col ORDER BY col2)
or partition. employees;
Returns the value from SELECT emp_name, salary, LAG(salary) OVER
LAG(col, [offset], [default]) OVER
LAG() the previous row in the (ORDER BY emp_name) AS prev_salary FROM
(PARTITION BY col ORDER BY col2)
table or partition. employees;
Fetches the first value in SELECT emp_name, salary,
FIRST_VALUE(col) OVER (PARTITION
FIRST_VALUE() an ordered partition of FIRST_VALUE(salary) OVER (ORDER BY emp_id)
BY col ORDER BY col2)
data. AS first_sal FROM employees;
LAST_VALUE(col) OVER (PARTITION SELECT emp_name, salary,
Fetches the last value in BY col ORDER BY col2 ROWS LAST_VALUE(salary) OVER (ORDER BY emp_id
LAST_VALUE() an ordered partition of BETWEEN UNBOUNDED ROWS BETWEEN UNBOUNDED PRECEDING
data. PRECEDING AND UNBOUNDED AND UNBOUNDED FOLLOWING) AS last_sal
FOLLOWING) FROM employees;
SELECT emp_name, salary, NTH_VALUE(salary,
Returns the nth value in NTH_VALUE(col, n) OVER (PARTITION
NTH_VALUE() 2) OVER (ORDER BY emp_id) AS second_sal
an ordered partition. BY col ORDER BY col2)
FROM employees;
Concatenates values of SELECT dept_id, LISTAGG(emp_name, ', ')
a column into a single LISTAGG(col, separator) WITHIN WITHIN GROUP (ORDER BY emp_name) AS
LISTAGG()
string, grouped by GROUP (ORDER BY col2) employee_names FROM employees GROUP BY
another column. dept_id;
Conditional & Null-handling Functions in Oracle SQL
Function Definition Syntax Example Query
SELECT emp_name, salary,
Used for conditional logic, similar CASE CASE
to IF-THEN-ELSE. Evaluates WHEN condition1 THEN result1 WHEN salary > 50000 THEN 'High'
CASE WHEN condition2 THEN result2 WHEN salary > 30000 THEN 'Medium'
conditions sequentially and
returns the first match. ELSE default_result ELSE 'Low'
END END AS salary_range
FROM employees;
Oracle-specific conditional
function that compares a given
SELECT emp_name,
DECODE expression to each search value. DECODE(expr, search1, result1, search2,
DECODE(dept_id, 10, 'HR', 20, 'Finance', 'Others') AS dept_name
Simpler alternative to CASE for result2, ..., default)
FROM employees;
equality checks.
Returns the first non-null value
COALESCE SELECT emp_name, COALESCE(bonus, salary, 0) AS payout
from a list of expressions. COALESCE(expr1, expr2, ..., exprN)
FROM employees;
Replaces NULL with a specified
NVL SELECT emp_name, NVL(bonus, 0) AS bonus_amt
replacement value. NVL(expr, replacement)
FROM employees;
Returns one value if the first
SELECT emp_name, NVL2(bonus, 'Bonus Given', 'No Bonus') AS
NVL2 expression is not null, and NVL2(expr, value_if_not_null, value_if_null) bonus_status
another if it is null. FROM employees;
Returns NULL if two expressions
NULLIF are equal; otherwise, returns the SELECT emp_name, NULLIF(salary, 0) AS salary_check FROM
NULLIF(expr1, expr2)
first expression. employees;
ROWNUM vs ROWID
Aspect ROWNUM ROWID
A pseudo column that assigns a sequential number to A pseudo column that returns the physical address of a row in
Definition
rows returned by a SQL query. the database.
Mainly used to limit the number of rows returned, such Used to uniquely identify and access a specific row quickly,
Purpose
as in pagination or filtering. especially in performance tuning and duplicate detection.
Alphanumeric string (represents row location in the database:
Value Type Numeric (starts from 1).
datafile, block, row, etc.).
No — Assigned dynamically and can change with Yes — Remains constant for a row unless it is deleted and
Fixed Value
different query conditions. reinserted.
- Used with WHERE ROWNUM <= n to fetch top N rows. - Used to identify rows directly.
Usage
- Often used for limiting result sets. - Useful in DELETE, UPDATE, and deduplication queries.
SELECT * FROM employees SELECT emp_name, ROWID
Example Query WHERE ROWNUM <= 5; FROM employees;
(Returns first 5 rows from result set) (Displays employee names with their physical row addresses)
INDEX
Definition An index is a database object used to speed up data retrieval by providing a quick lookup path to rows.
Purpose To improve the performance of SELECT queries, especially on large tables with frequent data access.
Automatically Created? Yes, automatically when a PRIMARY KEY or UNIQUE constraint is created.
Trade-off Increases read speed, but may slightly slow down inserts/updates/deletes due to index maintenance.
Syntax CREATE INDEX index_name ON table_name (column1 [, column2]);
Example CREATE INDEX idx_emp_name ON employees(emp_name);
Types of Index (B-Tree and Bitmap Index)
B-tree Index Bitmap Index
An index that stores data in a balanced tree structure for An index that uses bitmaps (0s and 1s) to represent
Definition
fast searching. row values.
Best For Columns with many unique values (High cardinality). Columns with few distinct values (Low cardinality).
Storage Usage Uses more space for columns with fewer values. Uses less space for columns with fewer values.
Example
employee_id, email, phone_number gender, status, marital_status
Columns
What is Partitioning?
Aspect Details
Partitioning is the process of dividing a large table (or index) into smaller, manageable parts, called partitions, based
Definition
on some column(s).
Purpose To improve query performance, manageability, and data availability.
Partition
The column based on which data is split into partitions.
Key
Types of Partitioning in Oracle
Example Partition
Type Definition Benefits Characteristics
Key
Divides data based on a Easy to manage time-based or Range Partitions are defined by order_date, salary,
Range
range of values. sequential data. value ranges. year
Divides data based on Useful when values are known List Partitions are defined by region, department,
List
specific, distinct values. and few (like categories). explicit values. status
Divides data randomly using Ensures uniform data Used when data values are customer_id, emp_id,
Hash
a hashing algorithm. distribution. unpredictable or skewed. product_id
VIEW
Aspect View Materialized View
A virtual table based on the result of a SELECT query. It does not A physical copy of the result of a SELECT query,
Definition
store data but shows data dynamically from the source tables. stored as a table that can be refreshed periodically.
To improve query performance by storing
To simplify complex queries, provide custom views, and
Purpose precomputed results for complex queries or
restrict access to certain data.
reporting.
No data storage. The data is retrieved dynamically each time Stores data physically like a snapshot, which can be
Storage
the view is queried. refreshed to stay current.
MERGE
Aspect Description
Definition The MERGE statement combines INSERT, UPDATE, and DELETE operations into one. It allows you to conditionally
update existing rows or insert new rows based on matching data between a source table and a target table.
- Update rows if a match is found.
Purpose - Insert new rows if no match is found.
- Can also delete rows under certain conditions (optional).
MERGE INTO target_table t
USING source_table s
Syntax ON (t.column_name = s.column_name)
WHEN MATCHED THEN UPDATE SET t.column1 = s.column1
WHEN NOT MATCHED THEN INSERT (column1, column2)
VALUES (s.column1, s.column2);
- target_table: The table you want to update or insert into.
Key - source_table: The table from which to retrieve new data.
Components - ON: Condition to match rows between the tables.
- WHEN MATCHED: Action to take when a match is found (typically UPDATE).
- WHEN NOT MATCHED: Action to take when no match is found (typically INSERT).
MERGE INTO employees e
USING new_employees ne
Example ON (e.emp_id = ne.emp_id)
WHEN MATCHED THEN UPDATE SET e.salary = ne.salary
WHEN NOT MATCHED THEN INSERT (emp_id, name, salary)
VALUES (ne.emp_id, ne.name, ne.salary);
Explanation - MATCHED: If emp_id exists in both tables, the salary is updated in employees.
- NOT MATCHED: If emp_id doesn’t exist in employees, a new record is inserted into employees.
Aspect Subquery Correlated Subquery
Definition A query inside another query that executes once and A subquery that depends on the outer query and executes
passes results to the outer query. once for each row of the outer query.
Purpose To return a result set used by the main query (e.g., filter To perform row-wise comparisons using values from the
or compare values). outer query.
Execution Executed independently of the outer query. Executed repeatedly, once for each row in the outer query.
Performance Usually faster (single execution). Slower due to multiple executions.
Use Case Filtering, checking existence, computing values. Comparing each row in a table with aggregated or filtered
data.
INLINE VIEW
➢ An inline view is a subquery written in the FROM clause of a SQL query. It acts like a temporary table that exists only during the
execution of that query.
➢ It’s useful when I want to perform operations like filtering, aggregation, or joins on derived data without creating a physical table
or view.
➢ For example, if I want to use the result of a GROUP BY as a table to filter rows, I can use an inline view.
A Common Table Expression (CTE) is a temporary result set in SQL that you can reference
within a `SELECT`, `INSERT`, `UPDATE`, or `DELETE` statement. It is defined using the
`WITH` clause, followed by the CTE name and the query. CTEs improve readability and
structure, especially for complex queries. They can also be recursive, allowing repeated
references to the CTE within itself.
CTE (common table expression) OR
1 Example :
WITH Clause
WITH HighSalaryEmployees AS (
SELECT employee_id, name, salary
FROM employees
WHERE salary > 50000
)
SELECT * FROM HighSalaryEmployees;
1. Primary Key : Primary key uniquely identifies each record in a table. It must contain
unique values and cannot contain NULL.
Example:
emp_id in an Employees table.
We cannot or contain NULL
UNIQNESS -> YES
MULTIPLE KEY -> NO
2. Foreign Key : A foreign key is a field in one table that refers to the primary key in another
table. It maintains referential integrity.
Example:
department_id in Employees table referencing department_id in Departments table.
ORACLE -Different types of keys in Untill we put constrait we cannot
2
Oracle UNIQNESS -> NO
MULTIPLE KEY -> YES
3. Composite Key : A composite key is a combination of two or more columns used
together to uniquely identify a record.
Example:
(student_id, course_id) in an Enrollments table.
In one column can contain NULL.
UNIQNESS -> YES
MULTIPLE KEY -> NO
4. Alternate Key : An alternate key is any candidate key not chosen as the primary key. It
can also uniquely identify records.
Example:
If email and username both can uniquely identify users, but email is chosen as the primary
key, then username is an alternate key.
Cannot contain NULL
UNIQNESS -> YES
MULTIPLE KEY -> YES
5. Candidate Key : Candidate keys are fields (or combinations of fields) that can qualify as
a primary key. There can be multiple candidate keys in a table.
Example:
In a Users table, both email and username can be candidate keys.
Cannot contain NULL
UNIQNESS -> YES
MULTIPLE KEY -> NO
6. Surroggate Key : A surrogate key is a system-generated unique identifier (usually a
number) used as the primary key instead of natural keys.
Example:
An auto-incrementing id column with no business meaning.
Cannot contail NULL
UNIQNESS -> YES
MULTIPLE KEY -> NO
When any DML action is ongoing then simlaneously other can not do DML action at same
time after finishing the DML no we can do ours i.e. while doing the only DML action lock
ORACLE - Lock Mechanism in mechanism is works
3
Database If we delete something at database level and didn't commit our acttion and in infromatica
we start the workflow then error occured as RESOURCE NOW WAIT that means COMMIT
means we releasing the lock
Feature Primary Key Surrogate Key Unique Key
Uniqueness Yes Yes Yes
Yes (one NULL per
Nulls Allowed No No
column)
ORACLE - Primary Key vs Surrogate Business
4 Yes (usually) No Yes (usually)
Key vs Unique Key Meaning
Count per
One Can have one (as PK) Many
Table
No (manually Yes (e.g., sequence or
Auto-generated No
assigned) identity column)
Have you done any performance optimization on long running SQL queries, what are the
different steps you performed to identify the root cause,
1) Explain Plan - Oracle Optimizer (Brain of Oracle, we can say) : In which we check the (i)
Full table Scan is going on or not if going on then its bad (ii) Index scan is going on or not
ORACLE - Query - Optimization or
5 which is Good if going on
Performance
2) Hints :- We use hints to tell oracle optimizer How you should execute your query (ex.
leading)
3) Restructure of query
4) We can create partition
A stored procedure is a named block of code (usually SQL and PL/SQL) that does
ORACLE - Stored Procedure, something — like inserting data, updating records, or fetching info — and is saved in the
6
Packages, Schema database so you can call it anytime without rewriting the code.
Packages : A package is like a folder or container that holds related stored procedures,
functions, variables, cursors, and more — all grouped together under one name.
Schema:
➢ In Oracle SQL, a schema is a collection of database objects that belong to a
specific user. These objects include tables, views, indexes, procedures, sequences,
synonyms, and more.
➢ Each user account is associated with one schema, and by default, the schema
name is the same as the username.
➢ Schemas help organize and manage database objects logically and securely.