Unit 5 DBMS LNU
Unit 5 DBMS LNU
1. Homogeneous Database :
In a homogeneous database, all different sites store database identically. The operating system,
database management system, and the data structures used – all are the same at all sites.
Hence, they’re easy to manage.
2. Heterogeneous Database :
In a heterogeneous distributed database, different sites can use different schema and software
that can lead to problems in query processing and transactions. Also, a particular site might be
completely unaware of the other sites. Different computers may use a different operating
system, different database application. They may even use different data models for the
database. Hence, translations are required for different sites to communicate .
A database link connection allows local users to access data on a remote database.
For this connection to occur, each database in the distributed system must have a
unique global database name in the network domain. The global database name
uniquely identifies a database server in a distributed system.
Type of
Link Description
Connected Users connect as themselves, which means that they must have an
user link account on the remote database with the same user name and
password as their account on the local database.
Fixed user Users connect using the user name and password referenced in the
link link. For example, if Jane uses a fixed user link that connects to
the database with the user name and password password, then
hq scott/
to scott directly, and all the default roles that scott has been granted in
the database.
hq
SQL snapshots are a recent read-only copy of the table from the database or a
subset of rows/columns of a table. The SQL statement that creates and subsequently
maintains a snapshot normally reads data from the source database server.
A snapshot is created on the destination system with the CREATE
SNAPSHOT SQL command. The remote table is immediately defined and
populated from the master table. These are used in data replication, reporting,
maintaining historical data, and dynamically replicating data between distributed
databases.
To create a simple snapshot based on a single table or a straightforward SELECT query from a
single table, you can use the following syntax:
1. Simple snapshots
2. Complex snapshots
Complex snapshot
CREATE SNAPSHOT sampleSnps1
FROM student
UNION ALL
FROM new_student;
Once snapshot is built on remote database, if node containing data from which the
snapshot is built is not available. Snapshot can be used without need to access the
unavailable database.
Data subsetting.
Disconnected computing.
Mass deployment.
Disadvantages of Snapshots in SQL
Applications of Snapshots
Protects data.
Recovers data when information is lost because of human error or corruption of data
Data dictionary
A Data Dictionary comprises two words i.e. Data which simply means
information being collected through some sources and Dictionary means where
this information is available.
The following data name type of Information is used to store in a data dictionary:
Name Description
Name generally includes the primary name of all composite data
Name or control items available, and the name of the external entity or
data store.
Aliases Any other word used in place of Name
A data dictionary generally gives information about where and
Where or How
how data or control items are used which may include an input/
it’s used?
output to process.
Description A notation for representing content
Aliases None
The main challenge that occurs in front of us is that a data dictionary is somehow
difficult and it may lead to take much time in case when data is not prepared
previously.
Data Preparation is a bit lengthy and hectic process for a large scale of data.
When you don’t do Data Preparation, Data Dictionary is not that much efficient.
It can be an expensive process when resources are not to be utilized efficiently.
Data Dictionary can be an insecure process as if you give access to so many
persons, it might be a challenge to the security of the Data Dictionary.
EQUI JOIN :
EQUI JOIN creates a JOIN for equality or matching column(s) values of the relative tables. EQUI
JOIN also create JOIN by using JOIN with ON and then providing the names of the columns with
their relative tables to check equality using equal sign (=).
Syntax :
SELECT column_list
FROM table1
JOIN table2
[ON (join_condition)]
4 Megha 2 Delhi
6 Gouri 2 Delhi
id class city
9 3 Delhi
10 2 Delhi
12 2 Delhi
SELECT student.name, student.id, record.class, record.city
FROM
student
JOIN
record
ON student.city = record.city;
name id classcity
Hina 3 3 Delhi
Megha 4 3 Delhi
name id classcity
Gouri 6 3 Delhi
Hina 3 2 Delhi
Megha 4 2 Delhi
Gouri 6 2 Delhi
Hina 3 2 Delhi
Megha 4 2 Delhi
Gouri 6 2 Delhi
NON EQUI JOIN performs a JOIN using comparison operator other than equal(=)
sign like >, <, >=, <= with conditions.
Syntax:
SELECT *
FROM table_name1, table_name2
WHERE table_name1.column [> | < | >= | <= ] table_name2.column;
name id city
Hina 9 Delhi
Megha 9 Delhi
Gouri 9 Delhi
name id city
Hina 10 Delhi
Megha 10 Delhi
Gouri 10 Delhi
Hina 12 Delhi
Megha 12 Delhi
Gouri 12 Delhi
OUTPUT
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:
Return all customers from a city that starts with 'L' followed by one wildcard character, then 'nE' and then
two wildcard characters:
SELECT * FROM Customers
WHERE city LIKE 'L_nE__';
Return all customers from a city that contains the letter 'L':
SELECT * FROM Customers
WHERE city LIKE '%L%';
Return all customers that starts with 'a' or starts with 'b':
ANY means that the condition will be true if the operation is true for any of the values in the range.
The following SQL statement lists the ProductName if it finds ANY records in the OrderDetails
table has Quantity equal to 10 (this will return TRUE because the Quantity column has some
values of 10):
SELECT ProductName
FROM Products
WHERE ProductID = ANY
(SELECT ProductID
FROM OrderDetails
WHERE Quantity = 10);
The following SQL statement lists the ProductName if it finds ANY records in the OrderDetails
table has Quantity larger than 99 (this will return TRUE because the Quantity column has some
values larger than 99):
SELECT ProductName
FROM Products
WHERE ProductID = ANY
(SELECT ProductID
FROM OrderDetails
WHERE Quantity > 99);
The SQL ALL Operator
The following SQL statement lists the ProductName if ALL the records in the OrderDetails table has Quantity equal to
10. This will of course return FALSE because the Quantity column has many different values (not only the value of 10):
SELECT ProductName
FROM Products
WHERE ProductID = ALL
(SELECT ProductID
FROM OrderDetails
WHERE Quantity = 10);
The SQL EXISTS Operator
The EXISTS operator is used to test for the existence of any record in a subquery.
The EXISTS operator returns TRUE if the subquery returns one or more records.
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID=
Suppliers.supplierID AND Price < 20);
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.Suppli
erID = Suppliers.supplierID AND Price = 22);
In Operator
Return all customers that have NOT placed any orders in the Orders table:
1. DBMS_FLASHBACK.Enable_At_System_Change_Number
Purpose: Enables Flashback Query to retrieve data as of a specific system
change number (SCN).
Syntax:
EXECUTE Dbms_Flashback.Enable_At_System_Change_Number(scn);
Parameters:
scn: The System Change Number (SCN) we want to enable Flashback
Query for.
How It Works:
1. Set SCN: The Enable_At_System_Change_Number procedure sets the
database to the state it was at the specified SCN. This allows you to
perform queries as if the database were in that state.
2. Query Data: After enabling, we can run queries to view the data as it was
at that SCN.
3. Revert: Once done, we can disable Flashback Query to return to the
current state.
2. DBMS_FLASHBACK.Enable_At_Time
Purpose: Enables Flashback Query to retrieve data as of a specific point in
time.
Syntax:
EXECUTE Dbms_Flashback.Enable_At_Time(date_time);
Parameters:
date_time: The timestamp we want to enable Flashback Query for.
How It Works:
1. Set Time: The Enable_At_Time procedure sets the database to the state it
was at the specified timestamp. This allows you to perform queries as if
the database were in that state.
2. Query Data: After enabling, we can run queries to view the data as it was
at that specific point in time.
3. Revert: Once done, we can disable Flashback Query to return to the
current state.