How can I generate a Date in SQL with GENERATED ALWAYS AS (XXX)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I generate a Date in SQL with GENERATED ALWAYS AS (XXX)?

I want to have a Date as primary key, which is automatically generated every time that the user enters a new entry. Is that possible?

5th Jan 2020, 5:10 PM
Sebastian Thomas
Sebastian Thomas - avatar
2 Answers
+ 1
I don't recommend that, since the primary key has to be unique. What if there are more than one entries made on a single day?
5th Jan 2020, 5:13 PM
Avinesh
Avinesh - avatar
0
It is not possible that there is more than one entry per day in this table. That's why the table's primary key should be this date: Every day certain values are saved in this table, but just in one row per day.
5th Jan 2020, 6:44 PM
Sebastian Thomas
Sebastian Thomas - avatar