Greetings,
I'm trying to update the columns of one table to contain values copied from a table in a different database.
The update statement I'm using is:
UPDATE loadbannerImpressions
SET isp = ip.ipISP,
region = ip.ipRegion,
city = ip.ipCity,
countryCode = ip.countryShort,
country = ip.countryLong
FROM loadbannerImpressions
INNER JOIN ip2location.dbo.ip2locationData ip
ON clientIPno BETWEEN ip.ipFrom AND ip.ipTo
WHERE memberNo = 0
The ip2location.dbo.ip2locationData is a table the contains approx 7 million records with regional data based on IP addresses.
Sample Data:
ipFROM ipTO countrySHORT countryLONG
---------------------- ---------------------- ------------ -----------------
0 33554431 - -
33554432 33685503 UK UNITED KINGDOM
33685504 50331647 UK UNITED KINGDOM
50331648 67108863 US UNITED STATES
67108864 67109119 US UNITED STATES
I've created non-clustered indexes on the ipFrom and ipTo columns as follows: create nonclustered index idx_ipFrom on ip2locationdata (ipFrom) ON FG_INDEXES create nonclustered index idx_ipTo on ip2locationdata (ipTo) ON FG_INDEXES
The loadBannerImpressions table contains approx. 500,000 rows.
The update statement tends to take a long time to execute, and I'm wondering if I'm going about this the wrong way. 500,000 rows, joining with a table of 7,000,000 rows is going to eat some CPU time, but I'm wondering if there's a better way I could be doing this?
Thanks,
Bill