-1

I want to save some sequence of digits, which may be a number (eg 12345, 1230) or not (eg 00123, 0120). Which type of column is the most effective (by memory, by indexing speed) for that purpose?

Also, I need to store strings of characters from specially defined alphabet (eg "digits and comma" or "digits and english letters and dots and commas"). How to effectively do this?

Can I set limits on CHAR/VARCHAR type of a column to reduce the memory size it takes?

Kirk Beard
  • 9,569
  • 12
  • 43
  • 47

2 Answers2

0

This is no different from any string column which implies varchar/text type.

VARCHAR(n) takes care of storage dynamically.

Reference here.


For constraining allowed symbols you could use CHECK constraints, but they don't work in MySQL so a workaround is to use trigger and define accepted characters there. See this question. You could use REGEXP function to define your allowed alphabet.

Kamil Gosciminski
  • 16,547
  • 8
  • 49
  • 72
0

For sql you can go with

varchar() and if your using POSTgreSQL you can make use of something known as citext

Chetan_Vasudevan
  • 2,414
  • 1
  • 13
  • 34