Untitled
Untitled
An Oracle VIEW, in essence, is a virtual table that does not physically exist.
Rather, it is created by a query joining one or more tables.
A view is a virtual table because you can use it like a table in your SQL queries.
Every view has columns with data types so you can execute a query against views
or manage their contents (with some restrictions) using the INSERT, UPDATE,
DELETE, and MERGE statements.
Unlike a table, a view does not store any data.
Continue..
Continue..
Also, one can use below pages for more detail:
https://www.oracletutorial.com/oracle-view/oracle-create-view/
Views are generally used when data is to be accessed infrequently and data in table gets
updated on frequent basis.
Example:
CREATE OR REPLACE VIEW SAMPLE_VW
AS
SELECT Department, SUM (Salary) AS TotalSal
FROM EmpDept
GROUP BY Department;
Continue..
When you create view, it just stores the name of the query, it won't store the data of the
result.
When you query a view:
SELECT * FROM ViewName
Since the view doesn't have any physical data, it always fetches from the base table.
Assignments:
1. What is the purpose of using the force option while creating views?
2. Create a view in your own schema and perform DML operations
3. Create a complex view. Can we perform DML operations on this, if so how can we
do it?
Quiz
Question: A view always fetch up to date data from the table because it runs it’s query
each time it receives a call, is this statement correct?
Question: Does the Oracle View exist if the table is dropped from the database?
Materialized View
A materialized view in Oracle is a database object that contains the results of a query.
A materialized view, is a table segment whose contents are periodically refreshed based on a query,
either against a local or remote table.
Materialized View Example
GROUP BY category_path1;
Difference b/w View and Materialized View
Views are not stored physically on the disk MV are stored on the disk.
View can be defined as a virtual table created MV is a physical copy, picture or snapshot of
as a result of the query expression. the base table.
View is just a display; it do not require memory MV utilizes the memory space as it stored on
space. the disk.
No need to refresh, since the data is directly MV can be set to refresh manually, on a set
fetched from base tables. schedule, or based on the database detecting a
change in data from one of the underlying
tables.
Partition allows table, index or index organized tables to be subdivided into smaller
pieces and each piece of table, index or index organized table is called as Partition.
List Partition
Hash Partition
Syntax:
1. Range Partition:
Create table TableName
When in the specified table the data is based on the (ColumnName1 datatype(size)….
specific date range, and it is properly divided in some ColumnName-n datatype(size))
range then user should go for the partitioned named as Partition by range(Column needs to be partitioned)
‘Range Partition’. (Partition PartitionName1 values less than(value1)….
Partition PartitionName-n values less than(maxvalue));
2. List Partition:
List partition enables you to explicitly control how the partition of tables need to be done by specifying list
of distinct values as partition key in description of each partition.
Syntax:
ListPartition.sql
Create table TableName
(ColumnName1 datatype(size)….
ColumnName-n datatype(size))
Partition by range(Column needs to be partitioned)
(Partition partitionName1 values less than(value1)….
Partition partitionName-n values less than(maxvalue));
3. Hash Partition:
Hash partitioning is type of partitioning where data is partitioned by using the hashing
algorithms. Different hashing algorithms are applied to partition key that you identify.
Syntax:
HashPartition.sql
Syntax: Suppose you want to add the partition to the existing table
named ‘Employee’ and partition it by using City column.
ALTER TABLE TableName Query used:
Modify ALTER TABLE Employee
Partition by PartitionName(Column_name)( Modify
Partition PartitionName values …… Partition by LIST(Employee_City)
) online; (
Partition P_Kolhapur values(‘Kolhapur’),
Partition P_Sangali values(‘Sangli’),
Partition P_OTH values(default)
) online;
Indexing
SQL Indexes are used in relational databases to quickly retrieve data. They are like indexes
at the start/end of the books whose purpose is to find a topic quickly. SQL provides Create
Index, Alter Index, and Drop Index commands that are used to create a new index, update
an existing index, and delete an index in SQL Server.
Data is internally stored in a SQL Server database in “pages” where the size of each page
is 8KB.
A continuous 8 pages is called an “Extent”.
When we create the table then one extent will be allocated for two tables and when
that extent is computed it is filled with the data then another extent will be allocated,
and this extent may or may not be continuous to the first extent.
Reference Link: https://docs.microsoft.com/en-us/sql/relational-databases/indexes/indexes?view=sql-
server-ver15