0

In my patient table, I want all the patient IDs to start with the 'PT' prefix. For example, PT01, PT02, ...

My code is:

CREATE TABLE patient
(
     p_id varchar(10) PRIMARY KEY CHECK(p_id in('PT%')),
     pname varchar(22)
)

It does not work... any suggestions?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • This is a secondary business-/client-side numbering. Which may be altered. This may be unique but you don't have to make it PK. Use surrogate `int identity` field - this will avoid a plenty of troubles with your magic STRING-NUMBERS. – Ivan Starostin Dec 12 '16 at 07:06

1 Answers1

0

You should use like

CREATE TABLE PATIENT
(
  P_ID  VARCHAR(10) PRIMARY KEY CHECK(P_ID  LIKE'PT%' ),
  PNAME VARCHAR(22)
) 
Munavvar
  • 802
  • 1
  • 11
  • 33
Tharunkumar Reddy
  • 2,773
  • 18
  • 32