Skip to content
Advertisement

Will a SQL view filtered by large datetime always provide current data?

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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement