Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2015 May Best way to store IP Address into Database System

Best way to store IP Address into Database System

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing about the effective storage of IP-Address into Database System.

Now let’s talk about four part of IP-Address.

E.g, 152.145.10.25

Many database developers or database designer store this IP-Address into one column which is VARCHAR(15).

What do you think? Is this effective storage of IP-Address?.

Now imagine that you are playing with 10,0,00,00 online customers in which all this IP-Address of the customer requires for analysis.

If we stored all IP-Addresses into one column, you have to perform string manipulation for finding a particular range of IP-Address.
The string operation is always costly and not advisable.


Effective storage of IP-Address is very simple:

Just divide your full-length IP-Address into four part.

E.g.

Full IP-Address: 152.145.10.25

Four Part :

152

145

10

25

Now create four tinyint/smallint column to store this four different part.

column like,

ip1 tinyint

ip2 tinyint

ip3 tinyint

ip4 tinyint

The full IP-Address split into four different integer part.

Now the task is very easy:
You can also apply an index on all this part and perform range analysis very quickly.

Yes, I agree that during insertion you also require splitting for storing in the different columns, but this is only a one time process after that you can easily use different parts for various analysis.

During select, you can also concat this four part and make full IP-Address for display purpose.

May 31, 2015Anvesh Patel
SQL Server Parameter SniffingHow to find size of Database and Table in PostgreSQL
Comments: 2
  1. Ron
    August 21, 2015 at 9:35 pm

    Ouch/yuck, using 4 separate fields for an IP address? That’s silly.

    Use a single unsigned int field and the inet_ntoa() and inet_aton() functions as needed.

    • Anvesh Patel
      Anvesh Patel
      August 22, 2015 at 6:46 am

      Yes you are right, This is also one of solution. I have stored IP Address into four different part because of analysis purpose. There are always multiple solution for single problem. But here I was facing problem for analysis of IP Address so solution is easy to divide into four different part.
      Thanks !

Anvesh Patel
Anvesh Patel

Database Engineer

May 31, 2015 Database DesigningAnvesh Patel, database, database concept, Database Design, database research and development, database standards, Database Theory, database topic, ip address, RDBMS, Storage
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....