In my web application, I have customer name and customer phone number. I should allow the same phone number multiple times. But I should not allow the same customer name to be entered multiple times. If there is already a customer named ‘Sean Patrick’ with mobile number ‘6039274849’. In future I should not allow a new user with same name (‘Sean Patrick’). But I can allow the same mobile number to be entered (‘6039274849’).
Assume the table structure as
CUSTOMER TABLE
columns
CUSTOMER_ID UNIQUE
CUSTOMER NAME
CUST_MOB_NUMBER
I am using Spring ROO. We will use HibernateJPA(aspectJ code) for database related stuffs.
Can anyone tell how to do this. As of now I am thinking of making 2 columns uique.
Is there any any way to make 2 columns unique together?
Assuming that the requirements make sense (it really doesn’t make sense to say that no two customers are going to have the same name– there are lots of John Smiths in the world). And people often have multiple mobile numbers.
You can declare both
customer_idandcustomer_nameas unique (thoughcustomer_idalmost certainly ought to be declared as a primary key, not merely unique)You an also declare a combination of two columns as unique