Reputation: 207
I have three columns below:
ID | Tag_name | View_name
--------------------------
12 | 23_GB_23 | screen1
13 | 23_GB_24 | screen2
How to generate Unique next value in ID based on Tag_name and View_name columns, Tag_name, View_name should be unique.
I was thinking on NOT NULL IDENTITY or using sequence_name.nextval and how to make sure only Tag_name, View_name unique values will be inserted, put Primary keys on this columns? is there any efficient way to manage this case?
thanks, S
Upvotes: 1
Views: 87
Reputation: 278
you can use composite primary key on these columns Primary key (Tag_name, View_name)
Alter table table_name
ADD PRIMARY KEY (Tag_name, View_name)
now only unique value will be inserted and this columns wont accept null. If you want the column to accept null then you can use UNIQUE CONSTRAINTS
Upvotes: 2