is there anyway to create lets say pattern for primary key i.e. for table products such pattern would by p-1,p-2… p-n etc.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, you can manually create and enforce that pattern into your application (or using triggers). A primary key just needs to be unique to work.
But I don’t recommend it. In your sample, seems
P-1have a business meaning. And, if it belongs to your business realm, it can be changed. While most database have aUPDATE CASCADEequivalent, it doesn’t change basic reason you shouldn’t use that as key: it’s information, not data.I suggest you to create a field named
ProductCode char(10) NOT NULL UNIQUEand maybe to fill it withP-00000001,P-00000002, and so on. Maybe you do prefer to use avarchar: this doesn’t matter, as it must fulfill your business requirement. Create anId INTEGER AUTO_INCREMENT PRIMARY KEYfield to use as primary key, as it doesn’t never needs to be changed.