How to place a unique index on two fields in a table.

anjiadmin
Tera Expert

I have two   the fields   field 1,field 2 in a table.

I want to keep unique index on those two fields..

How can we achieve this?  

9 REPLIES 9

ramireddy
Mega Guru

I guess, there is no provision for composite unique keys. However, you can write a "Data Policy" on the table. In that Data policy, write a script, which will check already records exists in that table with same values(Using GlideRecord)


Do you have the script for it.



Thanks,


Y Anji


Sorry,



I will take back my sentence that, there is no provision by default in SNOW. I missed the fact that, while creating index, we can select more than 1 column. Check the below screenshot. Select the table, In bottom, you can find "database indexes", click on new and add the columns into right slush buckets and click on "create index", this will create a composite unique key.



Screen Shot 2016-07-01 at 4.56.01 pm.png


Than you ram reddy.


It is working.


After placing the index...I am getting the error"


    java.sql.BatchUpdateException: Duplicate entry '6be744e14fd8a6409bec0f5d0210c73b-2016' for key 'contract'


    Invalid insert"


I want to replace that error with beautiful message.How can we do that.



Thanks,


Y Anji