presentation is on database for sql and stored procedures

harshsinghal08979 23 views 21 slides Aug 27, 2024
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

This presentation is on database that contains basics about data, normalization, indexing and stored prcedure that are current used in sql.


Slide Content

Database?

Index Database Fundamentals Covers the basic concepts and components of databases. Normalization Discusses the process of organizing data in a database to reduce redundancy and improve efficiency. Indexing Explores how indexing can improve the speed of data retrieval operations. Stored Procedure A precompiled set of SQL statements.

Database Fundamentals 1 Tables The basic unit of data storage in a database. 2 Primary Key A unique identifier for each record in a table. 3 Foreign Key A field in one table that uniquely identifies a row in another table. 4 Index Improves the speed of data retrieval operations.

Basic SQL Commands Data Definition Language (DDL) Commands: CREATE, ALTER, DROP Data Manipulation Language (DML) Commands: SELECT, INSERT, UPDATE, DELETE Data Control Language (DCL) Commands: GRANT, REVOKE

Normalization ?​

Types 1NF 2NF 3NF BCNF

First Normal Form(1NF) 1NF Ensures that the table has a primary key and each column contains atomic (indivisible) values.

Second Normal Form (2NF) 1 Meets 1NF The table meets all requirements of the First Normal Form. 2 Fully Functionally Dependent All non-key attributes are fully functionally dependent on the primary key.

Third Normal Form (3NF) Meets 2NF The table meets all requirements of the Second Normal Form. Functionally Dependent All attributes are functionally dependent only on the primary key.

Boyce-Codd Normal Form (BCNF) Meets 3NF The table meets all requirements of the Third Normal Form. Super Key For every functional dependency, the left-hand side is a super key.

Indexing Indexing is a powerful database optimization technique that improves the speed of data retrieval operations. Indexing allows databases to quickly locate and retrieve the desired records, reducing the amount of data that needs to be scanned.

Indexing Analogies Book Index Indexing in a database is similar to the index in the back of a book. Just as the book index allows you to quickly find information without reading the entire book, database indexes enable fast data retrieval without scanning the entire table. Road Map Indexes act as a roadmap for the database, providing a structured way to navigate the data and locate the desired information. This is especially useful for large datasets, where a full table scan would be slow and inefficient.

1 Index Creation An index is a data structure, such as a B-tree or hash table, that is built on one or more columns in a table. This index acts as a roadmap, allowing the database engine to quickly locate the desired data. 2 Query Optimization When a query is executed, the database engine first checks the index to determine the most efficient way to retrieve the requested data. This allows the engine to avoid scanning the entire table, dramatically improving query performance. 3 Ongoing Maintenance Indexes must be maintained as the underlying data changes, with updates to the index structure to ensure continued optimization.

Types of Indexes 1 Clustered Index A clustered index physically reorders the data in the table, based on the indexed column(s). This type of index is often used for the primary key column, as it can provide the fastest data retrieval . To create a clustered index: CREATE CLUSTERED INDEX idx_name ON table_name ( column_name ); 2 Non-Clustered Index A non-clustered index is a separate data structure that points to the actual data in the table. This type of index is more flexible, as it can be created on any column(s) in the table. To create a non-clustered index: CREATE INDEX idx_name ON table_name (column_name);

Index Storage Creating an Index: CREATE INDEX idx_student_id ON students( student_id );

Advantages and Disadvantages of Indexing Advantages Improved Query Performance: Indexes create pointers to where data is stored, speeding up retrieval. Efficient Sorting: Indexes help quickly sort and filter data. Enhanced Searching : Indexes reduce the amount of data scanned during search operations. Disadvantages Increased Storage Space : Indexes require additional disk space . Slower Write Operations : Inserting, updating, and deleting data can become slower due to index maintenance. Maintenance Overhead: Indexes need to be maintained, which can add overhead to the database system.

Stored Procedures   Definition: Stored procedures are precompiled SQL code that you can save, reuse, and execute in a database.​ Importance: Improve performance, security, and code reusability.​ ​

Creating and Executing Stored Procedures Procedure Definition Stored procedures are defined using the CREATE PROCEDURE statement, which includes the procedure name and the SQL statements to be executed. Parameter Passing Stored procedures can accept parameters, which allows for more flexibility and dynamic execution of the code. Procedure Execution Stored procedures are executed using the EXEC or EXECUTE statement, passing any required parameters.

Example:

Benefits Improved Performance Stored procedures are precompiled and optimized for faster execution, improving overall database performance. Enhanced Security Stored procedures can help reduce the risk of SQL injection attacks, improving the security of the database system. Code Reusability Stored procedures allow you to execute the same code multiple times without rewriting it, promoting code reuse and maintainability.

Questions ?