The best way to Keep an IP Address within a Repository
Each and every approach of storing the IP address has benefits and disadvantages. Major differences between the two involve sorting final results and accessing the information. The two main techniques of storing an IP handle are to retailer it as a variable character subject (varchar) or to store it as four separate integer fields, 1 represent every single octet of your street address.
Storing an IP address as a Varchar Subject in a Repository
The first procedure of storing an IP handle is to create a varchar discipline with a length of 15 characters. This permits the full IP address to be stored, including the periods separating each octet.
Positive aspects of Storing an IP street address as being a varchar
* The IP deal with displays exactly as entered.
* No additional computation is essential to search IP addresses for an precise match.
Disadvantages of Storing an IP tackle as being a varchar
* Sorting on IP deal with may perhaps result in undesired results. A standard sort will sort the IP 10.101.xx.xx before 10.11.xx.xx. (See Image for example)
* Searching for a partial IP street address match or all addresses within a specific range requires the use of a normal expression and or “like” command.
* Calculating unused IP addresses requires breaking the IP into individual octets and converting every single to an integer value.
* Verification of valid IP address entries must be carried out either making use of common expressions or making use of substring functions to break the IP into octects and converting every single octed to an integer.
Storing an IP tackle as an integer value
Positive aspects of Storing an IP tackle as an integer
* IP handle might be sorted in a very far more natural order. (See Image)
* Unused IP addresses are less difficult to identify. No conversion is vital.
* Validity of entered data might be very easily checked utilizing check constraints.
Disadvantages of Storing an IP address as an integer
* Displaying the IP address on query results needs concatenation of your four octets.
* Storing four integer values takes more space then storing one varchar value.
Further Considerations on How you can Shop an IP Address in a very Database
Storing the IP handle working with the 4 tiny integer fields, too as creating a single computed column in a varchar format would permit the repository designer to duplicate the effects of having the varchar field, enabling “like” and exact match searches as well as an simple display strategy.
Ultimately, the database designer is responsible for determining the way to store the IP address within the database based on user have to have, intended use in the data and storage requirements. If the repository designer chooses to use this strategy, they’ll need to work closely with the interface designer to ensure usability from the interface.