A view in the SQL query of any RDBMS of primary need is to protect BASE TABLE data. The view can be created without using ORDER BY and with the ORDER BY clause.
However, in many other cases, a view usually solves the formatting of DATEs. Let me take an example SQL query:
Create View Order_V5 AS SELECT Order_Number, Customer_Number ,TO_CHAR(Order_Date , 'MON, DD, YYYY') AS Order_Date ,TO_CHAR(Order_Total, '999,999.99') AS Total FROM Order_Table ;
When you give SELECT Query on the view, you can see converted DATES in the result:
Order_Number | Customer_Number | Order_Date | Total |
---|---|---|---|
123456 | 22222222 | MAY, 04, 2000 | 12,347.53 |
123512 | 55555555 | JAN, 01, 2001 | 8,005.91 |
123552 | 31323134 | OCT, 01, 2002 | 5,111.47 |
123585 | 87323456 | OCT, 10, 2003 | 15,231.62 |
123777 | 57896883 | SEP, 09, 1999 | 23,454.84 |
Real Learnings from the Views
- A view is a virtual table
- A view may define a subset of columns
- A view can even define a subset of rows if it has a WHERE clause
- A view never duplicates data or stores the data separately
- Views provide security
Top SQL View Advantages
- An additional level of security is provided
- Helps the business user not miss join conditions
- Help control read and update privileges
- Unaffected when new columns are added to a table
- Unaffected when a column is dropped unless it’s referenced in the view
Related Posts