-1

Is there a way to create a table in which the DATE column updated every date with the current date?

I want a column that every time I select gives me the current date.

GETDATE() function gives the current date but I don't manage to use it in order to get the current date every day.

The primary objective was to create a table, but I think it might be better to use a view.

0

2 Answers 2

8

You can create a computed column, as described here:

https://learn.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table?view=sql-server-ver15

Just because you can, doesn't mean you should, though.

A better way to do it would be to create a view like this:

 create view example_view as select *, getdate() as today from my_table 

Then call the view:

 select * from example_view 
3

Include the date function as part of your query:

SELECT ColA, ColB, GETDATE() AS [Date] FROM dbo.Table; 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.