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

Difference Between Views vs. Materialized View in Database: "Select Query"

Views are logical tables created by a SELECT query that dynamically retrieves data from underlying tables. Materialized views store the results of a query physically in a table to improve performance. The key differences are: 1) Views do not store results while materialized views do store results in a table. 2) Views always retrieve fresh data while materialized views require refreshing to get fresh data. 3) Materialized views generally have better performance than views due to storing results.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Difference Between Views vs. Materialized View in Database: "Select Query"

Views are logical tables created by a SELECT query that dynamically retrieves data from underlying tables. Materialized views store the results of a query physically in a table to improve performance. The key differences are: 1) Views do not store results while materialized views do store results in a table. 2) Views always retrieve fresh data while materialized views require refreshing to get fresh data. 3) Materialized views generally have better performance than views due to storing results.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

What is View in database?

Views are logical virtual table created by select query but the result is not stored anywhere in the disk and every time we need to fire the query when we need data, so always we get updated or latest data from original tables. Performances of the view depend upon our select query. If we want to improve the performance of view we should avoid to use join statement in our query or if we need multiple joins between table always try to use index based column for joining as we know index based columns are faster than non index based column. View allows storing definition of the query in the database itself. What is Materialized View in database? Materialized views are also logical view of our data driven by select query but the result of the query will get stored in the table or disk, also definition of the query will also store in the database .When we see the performance of Materialized view it is better than normal View because the data of materialized view will stored in table and table may be indexed so faster for joining also joining is done at the time of materialized views refresh time so no need to every time fire join statement as in case of view.

Difference between Views vs. Materialized View in database


Based upon on our understanding of View and Materialized View, Lets see, some short difference between them: 1) First difference between View and materialized view is that, In Views query result is not stored in the disk or database but Materialized view allows storing query result in disk or table. 2) Another difference between Views vs. materialized view is that, when we create view using any table, rowid of view is same as original table but in case of Materialized view rowid is different. 3) One more difference between View and materialized view in database is that, In case of View we always get latest data but in case of Materialized view we need to refresh the view for getting latest data. 4) Performance of View is less than Materialized view. 5) This is continuation of first difference between View and Materialized View, In case of view its only the logical view of table no separate copy of table but in case of Materialized view we get physically separate copy of table 6) Last difference between Views vs. Materialized View is that, In case of Materialized view we need extra trigger or some automatic method so that we can keep MV refreshed; this is not required for views in database. When to Use View vs. Materialized View in SQL Mostly in application we use views because they are more feasible, only logical representation of table data no extra space needed. We easily get replica of data and we can perform our operation on that data without affecting actual table data but when we see performance which is crucial for large application they use materialized view where Query Response time matters so materialized views are used mostly with data ware housing or business intelligence application. Difference between Varchar and varchar2 data types? Varchar can store up to 2000 bytes and varchar2 can store up to 4000 bytes. Varchar will occupy space for NULL values and Varchar2 will not occupy any space. Both are differed with respect to space. What is the use of NVL function? The NVL function is used to replace NULL values with another or given value. Example is NVL (Value, replace value) What the difference is between TRANSLATE and REPLACE? Translate is used for character by character substitution and Replace is used substitute a single character with a word.

What is a sub query and what are the different types of sub queries? Sub Query is also called as Nested Query or Inner Query which is used to get data from multiple tables. A sub query is added in the where clause of the main query. There are two different types of sub queries: Correlated sub query A Correlated sub query cannot be as independent query but can reference column in a table listed in the form list of the outer query. Non-Correlated sub query This can be evaluated as if it were an independent query. Results of the sub query are submitted to the main query or parent query. How do you view the last record added to a table? Latest Answer: select * from (select * from employees order by rownum desc) where rownum < 2; Why is inserting faster than delete? Which indexing technique works best for Oracle based database? Latest Answer: though they are different things but still actually what happens if we are deleting any Records oracle have to search the values which we are deleting from the tablespaces, indexes etc. but While we are inserting any record oracle just place Is it possible to update Views? If yes, How, If Not, Why? Latest Answer: A join view is defined as a view that has more than one table or view in its FROM clause (a join) and that does not use any of these clauses: DISTINCT,AGGREGATION, GROUP BY, START WITH, CONNECT BY, ROWNUM, and set operations (UNION ALL, INTERSECT) FORCE VIEW Specify FORCE if you want to create the view regardless of whether the base tables of the view or the referenced object types exist or the owner of the schema containing the view has privileges on them. These conditions must be true before any SELECT, INSERT, UPDATE, or DELETE statements can be issued against the view. If the view definition contains any constraints, CREATE VIEW ... FORCE will fail if the base table does not exist or the referenced object type does not exist. CREATE VIEW ... FORCE will also fail if the view definition names a constraint that does not exist. if you have mutual dependencies, e.g. between a package and a view, then you cannot create the view because of an invalid package and you cannot validate the package because the view does not exist. A workaround has been to create a dummy view, compile the package and create the actual view. Now you can force Oracle to create the view and then compile the package NO FORCE Specify NOFORCE if you want to create the view only if the base tables exist and the owner of the schema containing the view has privileges on them. This is the default. DENSE RANK This function computes the relative rank of each row returned from a query with respect to the other rows, based on the values of the expressions in the ORDER BY clause. The data within a group is sorted by the ORDER BY clause and then a numeric ranking is assigned to each row in turn starting with 1 and continuing on up. The rank is incremented every time the values of the ORDER BY expressions change. Rows with equal values receive the same rank (NULLS are considered equal in this comparison). A dense rank returns a ranking number without any gaps. This is as compared to RANK below. RANK This function computes the relative rank of each row returned from a query with respect To the other rows, based on the values of the expressions in the ORDER BY clause. The Data within a group is sorted by the ORDER BY clause and then a numeric ranking is assigned to each row in turn starting with 1 and continuing on up. Rows with the same Exact values of the order by expressions receive the same rank, however if two rows do receive the same rank ? the rank numbers will subsequently "skip". If two rows are #1, there will be no #2 ? rank will assign the value of 3 to the next row in the group. This is in comparison to DENSE_RANK which does not skip values.

select deptno, ename, sal, 2 dense_rank() over ( partition by deptno 3 order by sal desc ) dr, 4 rank() over ( partition by deptno 5 order by sal desc ) r 6 from emp 7 order by deptno, sal desc 8 / DEPTNO ENAME SAL DR R ---------- ---------- ---------- ---------- ---------10 KING 5000 1 1 CLARK 2450 2 2 MILLER 1300 3 3 20 SCOTT FORD JONES ADAMS SMITH 30 BLAKE ALLEN TURNER WARD MARTIN JAMES 3000 3000 2975 1100 800 2850 1600 1500 1250 1250 950 1 1 2 3 4 1 2 3 4 4 5 1 1 3 <<---4 <<---5 1 2 3 4 4 6

You might also like