Two monthes ago we have started a process of changing column type from smallint to int in a big database.
smallint
int
This was splitted in two phases:
The first part took almost two monthes to complete. Please read earlier post about the technique we have selected for the implementation. In total we have transferred about 15 billion rows. During this time database was online.
The second part was short but the problem was that we did not control all clients, so could not arbitrary change types of parameters and of result columns.
All our clients use Entity Framework 4 to access the database. All access is done though stored procedures. So suppose there was a procedure:
create procedure Data.GetReports(@type smallint) as begin select Type, ... from Data.Report where Type = @type; end;
where column "Type" was of type smallint. Now we were going to change it to:
"Type"
create procedure Data.GetReports(@type int) as begin select Type, ... from Data.Report where Type = @type; end;
where "Type" column became of type int.
Our tests have shown that EF bears with change of types of input parameters, but throws exceptions when column type has been changed, even when a value fits the range. The reason is that EF uses method SqlDataReader.GetInt16 to access the column value. This method has a remark: "No conversions are performed; therefore, the data retrieved must already be a 16-bit signed integer."
SqlDataReader.GetInt16
Fortunately, we have found that EF allows additional columns in the result set. This helped us to formulate the solution. We have updated the procedure definition like this:
create procedure Data.GetReports(@type int) as begin select cast(Type as smallint) Type, -- deprecated Type TypeEx, ... from Data.Report where Type = @type; end;
This way:
"TypeEx"
So there is a clear migration process.
P.S. we don't understand why SqlDataReader doesn't support value conversion.
SqlDataReader
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u