Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 PK suggestion needed

Author  Topic 

aiken
Aged Yak Warrior

525 Posts

Posted - 2003-01-13 : 19:23:39
I'm going to be importing a table of IP address ranges, with the addresses being 32 bit numbers.

Of course they'd fit into a 32 bit int, but then I'd have to deal with negative numbers when the high bit is set, or something like that.

Alternatively, I could just call the fields decimal for the sake of simplicity. How bad would that be?

Assuming I go with the int solution, the schema will be something like this:

start_num int NOT NULL,
end_num int NOT NULL,
various_attribute1 int,
various_attribute2 varchar(50),
various_attribute3 varchar(50)


...*every* lookup against this table will be in the form:
select various_attribute1,various_attribute2,various_attribute3 from IP where @iLookupIP between start_num and end_num


...Am I correct in thinking that the primary key should be on start_num and end_num? Or would using seperate indexes make more sense?

I appreciate any thoughts!

-b

SamC
White Water Yakist

3467 Posts

Posted - 2003-01-13 : 22:47:10
Storing IP addresses usually invokes healthy debate in the forum. If you are interested try the "Forum Search" for "IP Address". One post in particular that cites several considerations is

[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=21591[/url]

Most of these discussions run along the lines of how to store the IP address.

I can't offer an opinion about the primary key. I'm not sure what you need it for....

Anyone else?

Sam

Go to Top of Page

aiken
Aged Yak Warrior

525 Posts

Posted - 2003-01-14 : 00:43:42
Thanks for the link -- that does help. For the time being, I've decided to go with plain old ints, and it's working fine.

The primary key issue is basically to decide how best to search the table. Every single query that hits the table is going to be in the form:

select various_attribute1, various_attribute2, various_attribute3 from IP where @iLookupIP between start_num and end_num


...and I'm not sure how best to index the table for performance, as I've never really used BETWEEN before.

Cheers, and thanks.

-b

Go to Top of Page
   

- Advertisement -