At first, I am a noobie in databases and I learn this area now. So, maybe it's very easy but I don't know how all same.
I have an existing database where as primary key we use UUID
. But now, I need to add an order number for each row (i.e. 1, 2, 3, 4 and etc), i.e. the number value is not important, it requires only to it will be unique for each row and generates automatically.
I know that it's bad solution in the relation model but I can't change a primary key type by some reasons, so I need add yet column that will be anologue as if we used an Integer primary key with auto_increment
.
How can I make it? I tried to find a solution but everywhere says about a primary key only.
Asked
Active
Viewed 99 times
0

Denis Sologub
- 7,277
- 11
- 56
- 123
-
is it compulsory to add column in table , if not then you can generate row_number using t-sql function row_number which will be unique for each row – Chintan Udeshi Feb 02 '17 at 07:20
-
@ChintanUdeshi, sorry, can you explain more details? I really bad know SQL and databases generally. I need a column because our program supports only tables (without views and functions). So, I can't use any function to get a something from the database. – Denis Sologub Feb 02 '17 at 07:24
-
If you want to just display the row_number in query output then you can use t-sql function row_number rather than adding to DB let me know your purpose for row number then i can explain you better – Chintan Udeshi Feb 02 '17 at 07:27
-
@ChintanUdeshi, this number requires to our users can input it in our VCS when they will close tasks. And due to our Postgres data provider limits I need to add a real column. – Denis Sologub Feb 02 '17 at 07:30
-
You mean to say the row number will be entered by users or you need it to be auto generated? – Chintan Udeshi Feb 02 '17 at 07:34
-
@ChintanUdeshi, it will be auto generate in the database. Our program shows this number to the user. And he can input it after in our VCS service (it's a separate service). – Denis Sologub Feb 02 '17 at 07:36
-
ok then you should use the current timestamp which will be unique for each record extract(epoch from now()) – Chintan Udeshi Feb 02 '17 at 07:44
-
@ChintanUdeshi, yeah, thank you! I should have guessed. – Denis Sologub Feb 02 '17 at 07:53