Search code examples
pythonsql-serverimportssmsbackup

Import SQL server Management studio backup from an .ipynb file


I have a doubt regarding an ipynb file, it turns out that they send me a database to replicate the structure, they use SQL server Management studio, but I don't know how to import it. I thought it was a simple python script, which could create a SQL database , then Install anaconda, use %%sql statements to recreate it,

Until I realized that they could be imported in SSMS, but there is something that I am not doing well to import it correctly, I understand that it is a problem of correctly parsing the file,

import data

flat file ipynb

bad parse

I appreciate any help, thanks!

Install extensions in visual code, anaconda and the necessary libraries for handling SQL in Python, but it all boils down to correctly importing the file created in SSMS.


Solution

  • I would suggest you to follow the below steps:

    1. Open the notebook file in Jupyter notebook and copy all the cell contents as given below: How to copy multiple input cells in Jupyter Notebook
    2. Copy the content to a single .SQL file.
    3. In the Management Studio, open a new query window and open the file, created in step no. 2 and you can run the sql statements.

    SSMS New Query Window

    Note: Please review the SQL file once to see if everything is falling in place. You might need to add GO statements between batches. Also, it is recommended to put semicolon at the end of statements, to make them running without issues.