-2

Suppose I have a column called doctorID and the ID consisted of string characters and numbers how do I know which data type to use?

Could I use CHAR(11) or would it be better to use VARCHAR(11) when answering this question could you please share some examples of when to use the data types?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AdzT1
  • 61
  • 5

1 Answers1

0

@Anon. What's the difference between VARCHAR and CHAR?

VARCHAR is variable-length.

CHAR is fixed length.

If your content is a fixed size, you'll get better performance with CHAR.

If you use CHAR you may insert 5 chars in column CHAR(11) but after this 5 chars you'll have 6 whitespaces

Community
  • 1
  • 1
Ifch0o1
  • 900
  • 1
  • 14
  • 32
  • How do you mean by performance? This meaning faster, reliable? – AdzT1 Dec 22 '13 at 16:22
  • You didnt answer my 2nd question, would it be better to use CHAR(11) or VARCHAR(11) in my case, since the doctorID contains letters and numbers – AdzT1 Dec 22 '13 at 16:25
  • If (char length of doctorID === 11) every time, char(11) is better. But if doctorID char length is sometimes < 11 Varchar(11) is better. – Ifch0o1 Dec 22 '13 at 16:41