0% found this document useful (0 votes)
4 views

Assignment 2

Uploaded by

bgmiloverr123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 2

Uploaded by

bgmiloverr123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment-2

•Query to find third highest salary query in Database?


• What is the difference between Stored Procedure, Cursor and Trigger?
Cursor Trigger
•t is a pointer which is used to •It is a program which gets
control the context area and also executed in response to
to go through the records in the occurrence of some events.
database.
•A cursor can be created within a •A trigger cannot be created
trigger by writing the declare within a cursor.
statement inside the trigger.
•It gets created in response to •It is a previously stored program
execution of SQL statement thus
it is not previously stored.
•The main function of the cursor •The main function of trigger is to
is retrieval of rows from the result maintain the integrity of the
set one at a time (row by row). database
•It is activated and thus created •It is executed in response to a
in response to any SQL DDL statement, DML statement
statement. or any database operation.
• WHAT IS ACID PROPERTY, WHERE WE USE IT IN DAY TO DAY
ACTIVITY, WHAT ALL ARE DATABASE OPERATOR?

 ACID refers to Atomicity, Consistency, Isolation, and Durability. It is a set


of essential properties that defines and preserves the reliability of
transactions in database systems after executing a group of operations.
ACID properties ensure the integrity of data operations, safeguarding
against errors and concurrent access.

 We use it in the following day to day activities :


1. Transaction Management
2. Concurrency control.
3. Backup and Recovery Strategies

 SQL Operators refer to the diverse set of symbols and keywords used to
perform various operations on data in relational databases. These operators
include arithmetic, comparison, logical, bitwise, unary, assignment,
membership, NULL-safe equality, and concatenation operators, each
serving specific purposes in crafting efficient SQL queries.
• Difference between, Primary Key, Unique Key, Candidate Key , Foreign key?
Primary Key Unique Key
•It is used to serve as a unique •It is uniquely determines a row
identifier for each row in a table. that isn’t the primary key.
• It cannot accept NULL values. •It can accept NULL values.
•It has only one primary key. •It has more than one unique key.
•The primary Key is used for •The Unique Key is used for
indicating the rows uniquely. preventing duplicate entries.

Candidate Key Foreign key


•It is a super key with no repeated •It is a key it acts as a primary
data is called a candidate key. key in one table and it acts as
secondary key in another table.
•It can contain NULL values, and •It combines two or more
also contain unique values. relations (tables) at a time.
•The minimal set of attributes •They act as a cross-reference
that can uniquely identify a between the tables.
record
• What is the command to find, remove duplicate record from table and
how to count duplicate record in a table?

 SELECT column1, column2, COUNT(*)


FROM your_table
GROUP BY column1, column2
HAVING COUNT(*) > 1;
 WITH CTE AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER
BY (SELECT NULL)) AS rn FROM your_table)
DELETE FROM CTE WHERE rn > 1;
 SELECT column1, column2, COUNT(*) AS duplicate_count
FROM your_table
GROUP BY column1, column2
HAVING COUNT(*) > 1;
• Types of Join, Difference between Union and Union all, difference between
Haing and Group by Clause.
 Here are the different types of the Joins in SQL:

1. (INNER) JOIN: Returns records that have matching values in both


tables.
2. LEFT (OUTER) JOIN: Returns all records from the left table, and the
matched records from the right table.
3. RIGHT (OUTER) JOIN: Returns all records from the right table, and
the matched records from the left table.
4. FULL (OUTER) JOIN: Returns all records when there is a match in
UNION
either left or right table. UNION ALL
•The UNION removes •The UNION ALL remains all
duplicate rows from the rows, including duplicates,
result set, presenting only without any elimination.
unique records.
•The UNION involves the •The UNION ALL generally
additional step of performs faster, as it does
identifying and eliminating not have the overhead of
duplicates, potentially duplicate removal.
impacting performance
•The UNION creates a •The UNION ALL produces a
distinct result set with result set that includes all
• Difference between Having and Groupby
Clause.
Having Clause GroupBy Clause
•It is used for applying some •The group by clause is used to
extra condition to the query. group the data according to
particular column or row
Having cannot be used without •Groupby can be used without
groupby clause,in aggregate having clause with the select
function,in that case it behaves statement.
like where clause.
•The having clause can contain •It cannot contain aggregate
aggregate functions. functions.
•It restrict the query output by •It groups the output on basis of
using some conditions some rows or columns.
• WRITE THE COMMAND OF, HOW TO CREATE DATABASE,
HOW TO CREATE A TABLE, HOW TO CREATE SCHEMA IN DB.

 CREATE DATABASE your_database_name;


 CREATE SCHEMA your_schema_name;

 CREATE TABLE

your_schema_name.your_table_name (
id SERIAL PRIMARY KEY,
column1 VARCHAR(255) NOT NULL,
column2 INT,
created_at TIMESTAMP DEFAULT
CURRENT_TIMESTAMP
);
• What is Indexing, Type of Indexing, why we use it,
how to use it in day today activity.
 Indexing is a database optimization technique that improves the speed of data
retrieval operations on a database table. An index is a data structure that allows
for quick lookups and retrieval of rows from a database table based on the values
in one or more columns.
 Types of Indexing:

1. Primary Index
2. Secondary Index
3. Unique Index
4. Composite Index
5. Full-Text Index
6. Bitmap Index:
 Day to day activities are as follows:

1. Performance Improvement: Significantly reduces the time needed to retrieve data,


especially for large tables.
2. Efficiency: Helps in speeding up query processing and overall database
performance.
3. Data Integrity: Enforces uniqueness for data columns, maintaining data quality.
THANK YOU!

You might also like