-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.

8

You can create a computed column, as described here:

https://docs.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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.