My MSSQL database is corrupt and I can not get to my predictive models. Now what? Stellar to the rescue.

Small project database, with old backup, ended up in corrupt state. This happened.  A corrupted database; all-in-all 150MB.  I was super annoyed. Let alone, I had some R and Python code there and some – yes 🙂 – predictive models, I forgot to have automated backup created. Data stored in database should not be a problem, but the table with last stored model was the information / row, I needed

So the problem with serialized models stored in a table is, that it needs to be fully compatible and correctly restored to the last bit in order for R / Python to be read correctly. So missing one bit, and the model is literally useless.

My models are stored in T-SQL Table:

FROM [SQLR].[dbo].[Predictive_models]

Once I calmed my self down, I started with my options. Worse case scenario, I can restore two-months old backup, but what are my other options?

Using the Microsoft built-in Database Console Command


utility.  The utility comes with multiple repair options to resolve corruption errors in MS SQL database.  But, yeah,  not that it is a super challenging but I started to repair with option:


and it ended with data loss. Hurray for the better restore.  But still was not successful enough due to the data loss.

Digging further, I used  PowerShell Restore-SqlDatabase cmdlet for restoring SQL Server database. But, was left empty-handed, since this works only with when you have a restorable backup.

Digging for further information, I googled up and came to this blogpost, by Stellar. Next thing you know, I am downloading the software, and looking back now, I was the best choice.


The benefits using Stellar software repair for MS SQL Server:

  • Comes with a simple to use GUI which makes the repair process straightforward.
  • Helps repair SQL database quickly in three simple steps: 1. Select database file. 2. Repair database file. 3. Preview and Save repaired file.
  • Recovers all major database components of SQL server including tables, views, indexes, stored procedures, etc.
  • Resolves corruption errors in databases running on MS SQL Server 2019, 2017, 2016, and older versions

Additional Benefits:

  • Repairs SQL tables with PAGE and ROW compression.
  • Allows saving the repaired file in MS SQL, HTML, XLS, and CSV formats
  • Provides Windows and SQL authentication options to connect to the server
  • Supports Standard Compression Scheme for Unicode (SCSU) for SQL Server 2008 R2.

(based on the info/sales text from their website)

Step-by-step to repair corrupt .mdf file with Stellar Repair for MS SQL Server

After downloading, stop the MS SQL Server service and copy database (mdf. file) to different location.

1. The Instruction window is displayed. Click OK.

1-Software Instruction

2.  Select Database window appears. Click Browse to select .mdf file you want to repair.

2-Main Interface

Great feature is also, the ability to recover deleted database records; in this case select ‘Include Deleted Records’ checkbox (and make sure that you have the appropriate database recovery model selected).

After selecting the desired file, click repair to engage the process. Hopefully only one mdf file is corrupt 🙂 But you can also select multiple.

3-Selected database

There is also the ability to select the SQL Server version if the software is not able to detect the MSSQL Server database file version.  In this case, just  select the version of the SQL Server where your database was originally created.

4-Select Version

After the process completes with recovery, you can inspect what has been recovered by Stellar.

2020-01-16 08_48_03-Photos


 And I can recover only selected table and prior to recovering / saving, I can also inspect the content of my data in right pane.  Since the models are serialized and stored as blob, I can only hope that R will be able to de-serialized it and used it again using sp_execute_external_script.

Save the data back to  MDF file and later attach it to the SQL Server or in my case, exporting to CSV file is also a possibility since the table was not that big.

After attaching back new MDF file with table holding the models:

2020-01-16 08_55_13-SQLQuery8.sql - SNTK.UmbriaPrediction (SNTK_Tomaz (77))_ - Microsoft SQL Server

i’m able to run successfully the R script and score new values.

After all, I am happy that I found this software that helped me dealing with corrupt table / database and I can score the data on my older model that has great accuracy.

As always, happy coding!

Tagged with: , , , , , , , ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Follow TomazTsql on
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Programs I use: Scraper API
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (


Top SQL Server Bloggers 2018

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond


A daily selection of the best content published on WordPress, collected for you by humans who love to read.


Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond


Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Ms SQL Girl

Julie Koesmarno's Journey In Data, BI and SQL World


R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Server Insane Asylum (A Blog by Pat Wright)

Information about SQL Server from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...

SQLPam's Blog

Life changes fast and this is where I occasionally take time to ponder what I have learned and experienced. A lot of focus will be on SQL and the SQL community – but life varies.

%d bloggers like this: