title: Using Python to Automate "Generate Scripts" option in Management Studio to get the data from local SQL Server and save it in a .sql file
body: <p>I want to use Python to automate the "Generate Scripts" option in Management Studio so that I can get the data from tables which are stored on local SQL Server and save it into a <code>.sql</code> file. </p>
  
  <p>I want to save it in an SQL file so that later another user can access and verify the data on SSMS, even if he does not have access to the local SQL Server.</p>
  
  <p>Thanks! Any help would be appreciated as I have been trying this for sometime now. </p>
  
  <p>I tried using dataframes to fetch the data from SQL Server and then writing it into a csv file. Then I am not able to store it in a <code>.sql</code> file from csv.</p>