0

I work currently in a DWH. A big part of my job is to move data from some OLTP Database to the DWH.

One practice that we do is:

  1. -Create the new table that we need.

    create table Mytable
     (Column1   date, 
      Column2   varchar(8));
    
  2. -Create a view for the new table (exactly the same)

    create view Myview as select * from dummy
    alter view Myview  (
      Column1
     ,Column2
      ) as
       select
         Column1
         column2
        from Mytable
    
  3. -Read from that View

    here come one procedure that use Myview and not Mytable. why?

I understand of course the functionality of Views for reducing complexity in a save querys or that they are good to protect parts of the table to some final users.

But I can not see why is a good practice to read from the view and not direct from the Table.

I mean of course the case where the View is exactly the same as the Table.

Thanks for your answers , Enrique

Enrique Benito Casado
  • 1,914
  • 1
  • 20
  • 40

2 Answers2

2

This question is dangerously close to asking for an opinion.

But, views are often recommended for such a system because they isolate users from the underlying data structure. In other words, you can maintain the data and not have to change queries in user applications.

In addition, views are a convenient way to add in computed columns. The computed columns often contain business rules. Having the logic in a single place prevents the proliferation of business logic -- and the errors and the inconsistencies that can arise over time.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Views are Precompiled Query... So the Performance will better than writing select query each time and running it... Bcoz each time when u hit the same select query, it will get compiled and provide the result. But when u write the same query into a View and hit it, it will compiled only once and from the next time it wnt compile , it will provide the result instantly...

This is according to me..

Nagarajan
  • 1
  • 1
  • 1
    This is not true in the general case, though you can use indexes on MS SQL Server to speed up reads from a view. https://stackoverflow.com/questions/439056/is-a-view-faster-than-a-simple-query – Neville Kuyt Aug 21 '17 at 11:11