Monday, August 7, 2023

FLASHBACK vs roll back

 

FLASHBACK vs Roll back


Flashback should be used to undo changes that have been made outside of a transaction, while rollback should be used to undo changes that have been made within a transaction. However, the specific command that you use will depend on the specific situation.


Feature

Flashback

Rollback

Transactional

No

Yes

Can be used to undo changes made outside of a transaction

Yes

No

Can be used to restore the database to a specific point in time

Yes

No

Can be used to restore the database to the most recent checkpoint

Yes

No

More powerful tool for recovering from errors

Yes

No

Can be used to maliciously alter the state of the database

Yes

No




Oracle and SQL are both database management systems (DBMS).


Oracle is a commercial DBMS that is owned and developed by Oracle Corporation. It is a mature and robust DBMS that is used by many large organizations. Oracle is known for its scalability, performance, and security.

SQL (Structured Query Language) is a programming language that is used to manage data in a database. SQL is a standard language that is supported by all major DBMSs, including Oracle. SQL is used to perform tasks such as creating, querying, updating, and deleting data in a database.

In short, Oracle is a DBMS, while SQL is a programming language that is used to manage data in a database.


Differences Between Some of The Most Popular Oracle Versions:

Version

Release Date

Features

Oracle 12c

2013

In-memory columnar database, JSON support, and pluggable database

Oracle 11g

2007

Real Application Clusters (RAC), Oracle Data Guard, and Partitioning

Oracle 10g

2004

Data Pump, Flashback technology, and Transparent Data Encryption (TDE)

Oracle 9i

2001

XML support, Oracle Streams, and Partitioning

Oracle 8i

1997

Object-Relational features, Oracle Streams, and Partitioning

  

Feature

SQL Server

SQL

Type

Commercial RDBMS

Programming Language

Owner

Microsoft

ANSI

Scalability

Very scalable

Scalable

Performance

Very high performance

High performance

Security

Very secure

Secure

Supported Platforms

Windows, Linux, macOS

All major platforms

Cost

Commercial license required

Free to use

  •  SQL Server is a commercial RDBMS that is developed and marketed by Microsoft. It is a powerful and scalable database system that is used by many large organizations. SQL Server is known for its high performance, reliability, and security.



User-defined functions (UDFs)


CREATE FUNCTION dbo.Fibonacci (@n INT) RETURNS INT AS BEGIN IF @n = 0 RETURN 0; ELSEIF @n = 1 RETURN 1; ELSE RETURN dbo.Fibonacci(@n - 1) + dbo.Fibonacci(@n - 2); END;

This function takes an integer as input and returns the Fibonacci number for that input. For example, the following query will return the 5th Fibonacci number:

SELECT dbo.Fibonacci(5);

This query will return the value 5.

UDFs can be used to perform a variety of tasks, such as:

  • Calculating complex formulas
  • Formatting data
  • Validating data
  • Encrypting and decrypting data
  • Sending email
  • Making web service calls

UDFs can be very useful for improving the performance and scalability of your database applications. Here are some tips for using UDFs effectively:

  • Only create UDFs when necessary. If you can avoid creating a UDF, then do so.
  • Make sure your UDFs are efficient. UDFs should be as efficient as possible to avoid slowing down your database application.
  • Test your UDFs thoroughly. Make sure your UDFs work as expected for all possible inputs.
  • Document your UDFs. Document your UDFs so that other developers can understand how to use them.
===========

Cursor is a temporary work area that is used to iterate through a set of data. Cursors can be used to perform complex operations on large datasets, but they can also slow down your database application if they are not used carefully.


DECLARE @cursor CURSOR FOR SELECT * FROM Customers; OPEN @cursor; FETCH NEXT FROM @cursor INTO @customer_id, @customer_name, @customer_address; WHILE @@FETCH_STATUS = 0 BEGIN PRINT @customer_id; PRINT @customer_name; PRINT @customer_address; FETCH NEXT FROM @cursor INTO @customer_id, @customer_name, @customer_address; END; CLOSE @cursor; DEALLOCATE @cursor;

This query declares a cursor named @cursor that selects all rows from the Customers table. The OPEN statement opens the cursor, and the FETCH NEXT statement fetches the first row from the cursor. The WHILE loop iterates through the cursor, printing the values of the customer_id, customer_name, and customer_address columns for each row. The CLOSE statement closes the cursor, and the DEALLOCATE statement deallocates the cursor.

Cursors can be very useful for complex operations on large datasets. However, they can also slow down your database application if they are not used carefully. Here are some tips for using cursors effectively:

  • Only use cursors when necessary. If you can avoid using a cursor, then do so.
  • Use a cursor only for a limited number of rows. If you need to iterate through a large number of rows, then consider using a stored procedure or a trigger instead.
  • Close and deallocate the cursor as soon as you are finished using it. This will free up resources and improve performance.
  • Use the FETCH NEXT statement instead of the FETCH ALL statement. The FETCH ALL statement will fetch all rows from the cursor into memory, which can slow down your database application.


Stored procedures are a collection of SQL statements that are saved as a single unit. They can be executed by name, which can improve performance by reducing the number of times that the database has to parse and execute SQL statements. Stored procedures can also be used to encapsulate business logic, which can make your code more modular and reusable.

Triggers are special stored procedures that are executed automatically when a specific event occurs, such as a row being inserted, updated, or deleted. Triggers can be used to enforce data integrity, perform complex calculations, or send notifications.

Cursors are temporary work areas that are used to iterate through a set of data. Cursors can be used to perform complex operations on large datasets, but they can also slow down your database application if they are not used carefully.

 Differences between stored procedures, triggers, and cursors:

Feature

Stored procedures

Triggers

Cursors

Purpose

To encapsulate business logic and improve performance

To enforce data integrity and perform complex calculations

To iterate through a set of data

Execution

Manual or automatic

Automatic

Manual

Performance

Can improve performance, especially for complex queries

Can slow down performance if not used carefully

Can slow down performance if not used carefully

Portability

Portable, can be used with any relational database

Not portable, only works with SQL Server

Not portable, only works with SQL Server

 

No comments:

Post a Comment