Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Data Type to store build versions

What data type should i use for a SQL column to store Product version eg.

Version
0.1
0.1.1
0.2
1.1
1.1.647
2.0
.....

In query i should be able to sort them based on version number and i want an optimal query to find highest number.

Thanks

like image 552
nin Avatar asked Jul 31 '10 18:07

nin


People also ask

How do you store a version number in a database?

There is no generally-accepted place to store a version number in a database schema. Databases don't have version numbers by convention. There is no standard way of putting in this or any other information about an application into the database.

Which datatype is used to store date in SQL?

SQL data types can be broadly divided into following categories. Numeric data types such as int, tinyint, bigint, float, real, etc. Date and Time data types such as Date, Time, Datetime, etc. Character and String data types such as char, varchar, text, etc.

Should I use int or Bigint?

The int data type is the primary integer data type in SQL Server. The bigint data type is intended for use when integer values might exceed the range that is supported by the int data type. bigint fits between smallmoney and int in the data type precedence chart.

Which data types are used to store whole numbers SQL?

Numbers in SQL can be either exact (NUMERIC, DECIMAL, INTEGER, BIGINT, and SMALL INT) or approximate (DOUBLE PRECISION, FLOAT, and REAL). The integer data type is used to store whole numbers (numbers without the decimal point or simply nondecimal numbers).


2 Answers

A good solution would be to use an integer building the value to store like so:

MAJOR * 10000 + MINOR * 100 + Revision

Assuming each one can range from 0..99. If you want to go 0..999 use

MAJOR * 1000000 + MINOR * 1000 + Revision

This will sort properly, will query easily, is compact (1 int column), is easily decomposed and can even be decomposed visually.

like image 69
Erik Kangas Avatar answered Sep 17 '22 07:09

Erik Kangas


I would consider storing each part of the number in a separate TINYINT/SMALLINT field.

like image 31
Mchl Avatar answered Sep 19 '22 07:09

Mchl