In one of my Java EE applications, I used a registration page to register new user and as soon as one registers, his/her registered values will be inserted into Oracle database. But there is no way of detecting duplicate values. So I thought about adding unique constraint to some column values. But later I learned, I can’t declare more than one column as unique( In my case I already declared userid as primary key). But I need to make more than one column values unique (like emialid field). Again only adding unique can’t help as if a user submits a form with duplicate value an exception will be caught and user won’t be able to understand as he will be redirected to a blank page. So I have 2 questions.
1) How can I inform the user about inserting duplicate values?
and
2) How can I make more than one column unique in Oracle?
N.B. I don’t know javascript!!
First, you certainly can declare multiple unique constraints on a table. You can declare that
useridis a primary key and then declareemailidas unique. You can declare as many unique constraints as you’d like.Second, your application would need to catch the duplicate key constraint and do something useful with it. Redirecting the user to a blank page would not be useful– your application ought to catch the constraint exception and present a useful message to the user. For example, if you get an exception stating that the constraint
UK_EMAILIDwas violated, you’d probably want to present an error message to the user saying something along the lines of “This email address already exists.”