What is the best data type for field with format like this X.X.X.x
Here is the sample field data
15.8.0
15.8.1
15.8.2
15.8.3
15.8.4
1.8.0
2.8.2
9.8.2
9.8.3
9.8.4
10.8.0
13.15.0.1
13.15.1.1
13.15.2.1
13.15.3.1
13.15.4.1
13.0.0
26.0.0.1
26.0.0.2
This field use as primary field of table
Thanks
Best Answer
I can't say it would be the best ("best" in what sense?) but one way to do this is to have the 4 numbers in 4 separate
TINYINT
columns.You can have the
PRIMARY KEY
as a composite 4-column one or as a persisted column. Considering from the data provided that the 4th number can beNULL
, I'd choose the persisted as primary key and add a unique constraints on the 4 columns:Tested at rextester.com.
Another option would be to use the
HierarchyID
type.