I do have two tables:
1. PersonAddressList [About 5,000 records]
Columns:
ID int
TITLE varchar
CITY varchar
2. CityList [About 5,000 recods]
Columns:
ID int
City_Name varchar
City_State int //[RK to State]
Previous designer had added city names directly in table 1 [personaddresslist]. Now I am normalising it and replacing the city name in table 1 with city id in table 2
Query I have used:
Update personaddresslist, CityList set CITY = cityList.ID where CITY = City_name
The above query runs good if the tables have less data, but keeps on rolling n rolling in case of both tables has large no of data. In my real scenario I do medium set of data about 5000 records in each table.
So how do can we tune it fine.
Regards, Kabindra
Edit 1: Regarding the result from above query, it took me nearly 40 mins to complete the running of script, Since I need to run the similar script on other more tables, I would like to fine tune and make it faster.
Your table needs some modification and indexes to make it faster.
city
inPersonAddressList
table and the data type isvarchar
so even if its indexed it will never use it since they are of different data type in both tables.I will start with
Then will use the following update command
The above query will be faster, just make sure that both
CITY
andCity_Name
are of same data type with the same size before applying the indexes.Once the data is updated then you need to fix the structure
and finally make sure that the
CityList
ID
is indexed and if its primary key which is most likely it will be indexed by default.