If you must use an IPAddress as a primary key then I would strongly
recommend that you split it into 4 numeric fields with a Byte datatype. You
will have to use a compisite unique index, combining the 4 columns.
Further you should add appropriate constraints to different columns to
ensure that you have valid IPs
Here is a partial list for you:
- Loopback address range 127.xxx.xxx.xxx should be excluded
- 0.0.0.0 (default IP) and 255.255.255.255 and (Broadcast) should be
excluded
- Class D & E addresses should be Excluded (right?)
- What about Private IP addresss ranges (RFC1918) Include? Exclude?
- 10.xxx.xxx.xxx, 172.16.xxx.xxx to 172.31.xxx.xxx, 192.168.xxx.xxx?
I can almost bet that this is an internal project and you want to address
private IP address ranges only.
Are you planning to forgo DHCP and use static IP addresses or Address
reservations for everything?
If external IP addresses, how do you plan to account for IP address changes
in a world that predominantly uses dynamic IP addresses?
What happens when IPv6 kicks in? Yes, the IPv4 address is embedded in the
IPv6 address, but shouldn't you expect duplication as time goes on?
IP addresses are not good candidates for primary keys in most circumstances,
so please consider carefully before proceeding.
HS