3 Top Rules to Create a View in SQL

Here are basic rules you need to create a view. I have shared already what is read only view and updatable view.

View is a logical table. On top of base table yoy can create it. Here are three rules.

  1. No ORDER BY inside the View CREATE

  2. All Aggregation needs to have an ALIAS

  3. Any Derived columns (such as Math) needs an ALIAS

Here’s Sample SQL to create View

 CREATE View Department_Salaries AS
 SELECT     Dept_No
            ,SUM(Salary) as SumSal
            ,SUM(Salary) / 12 as MonthSal
 FROM Employee_Table

The above is the query to create a view. You can read one more example to create a view.

However, the SQL below is to retrieve data from SQL query

 FROM Department_Salaries
 Order By 1 ;
Dept_No    SumSal    MonthSal
________  ________  __________
     ?    32800.50   2733.38
    10    64300.00   5358.33
   100    48850.00   4070.83
   200    89888.88   7490.74
   300    40200.00   3350.00
   400   145000.00  12083.33

Also read how Salesforce is using AI without SQL for your quick reference.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.