krthkskmr
krthkskmr

Reputation: 471

Primary key using a predefined format in sql

I am trying to create a table that will generate a primary key automatically using a predefined format. Like this:

Customer_ID    Name   Phone
cust_1         Abc    123
cust_2         Def    456

Here Customer_ID is auto generated primary key.

Upvotes: 0

Views: 56

Answers (1)

LoztInSpace
LoztInSpace

Reputation: 5697

typically you just generate the number and the rest of the fluff (CUST_ in your case) is presentation.

If it's really important you can have a computed column that adds on the prefix - just make sure you put indexes and unique constraints where they need to be.

Upvotes: 1

Related Questions