0

If I create a view today for a table that continuously keeps getting data, using date filtering from 1900 and 2100, for example, will that "copy" become truncated to the moment that I build the view or since it is being filtered to a very large date will it keep showing the current data to the users that can access it?

GMB
  • 216,147
  • 25
  • 84
  • 135
Eunito
  • 416
  • 5
  • 22

1 Answers1

1

If I create a view today for a table that continuasly keeps getting data, [...] will it keep showing the current data to the users that can Access it?

Yes. A view does not actually stores data, it is just a sql query. Whenever you access the view, that sql query is executed under the hood. So basically a view always reflect the data that is stored in its underlying, physical tables.

Here is the small demo that demonstrates this behavior:

create table mytable (id int, val varchar(5));
insert into mytable(id, val) values(1, 'foo')

create view myview as select id, val from mytable;
select * from myview;
id | val
-: | :--
 1 | foo
insert into mytable values(2, 'bar');
select * from myview;
id | val
-: | :--
 1 | foo
 2 | bar
GMB
  • 216,147
  • 25
  • 84
  • 135
  • 1
    A Pointer basically then? No space ocupied even if I create hundreds of views based on huge tables? I knew it would create a virtual copy based on the select and it would be allways accessible but allways had this dates/space doubt.... – Eunito Apr 18 '20 at 18:33
  • 2
    @Eunito: yes, you are correct. The database dictionnary just stores the definition of the view, there is no physical storage. – GMB Apr 18 '20 at 18:57