7.2. Storing an IP Address in SQL

While not exactly a data type, IP addresses are being used as unique identifiers for people or companies. If you need to verify them, you can send an e-mail or ping them. There are three popular ways to store an IP address: a string, an integer, and a set of four octets.

In a test conducted in SQL Server, all three methods required about the same amount of time, work, and I/O to return data as a string. The latter two have some additional computations, but the overhead was not enough to affect performance very much.

The conclusion was that the octet model with four TINYINT columns had two advantages: simpler programming indexes on individual octets, and human readability. But you should look at what happens ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.