Suppose I have one table that have 5 columns:
Id int primary key
Date datetime
Value double
Fund_id reference
FundModel_id reference
FundDataField_id reference
This table have 37 000 000 rows.
Each fund have about 4000 rows.What is the best and quick way to delete rows from this table. I need to delete about 7000000 rows at a time but it takes about 10 minutes and by me this is a lot.
Currently I delete rows by Fund_Id , something like this:
Delete from FundYearDetail where Fund_id In (2054,2056,2058,2059,2061,2063,2064,2065,2066,2067,2069,2072,2073,2076,2078,2079,2080,2081,2082,
2086,2088,2090,2093,2095,2096,2097,2099,2101,2102,2103,2104,2105,2106,2107,2109,2110,2114,2115,2116,2117,2118,2119,2342,2125,2126,2127,2128,2129,2130,2131)
This statement will affect about 200 000 rows and will take very long time to complete , dividing this statement into 2 queries I am getting better performance , about 4 seconds each.
Does anybody know a better solution for this ?
Note:I am using Fluent NHibernate for data access if somebody know a better solution using Nhibernate please tell me. What if I will do a store procedure , will this increase my performance? Thanks.