Last post Jul 14, 2017 11:59 AM by JohnsonWelch
Jul 13, 2017 11:34 AM|JohnsonWelch|LINK
I am working on SQL Server 2014 and looking for the way to convert .mdf to .sql script online. So Is there any way that I can generate script with data in SQL Server ?
Jul 13, 2017 11:54 AM|bbcompent1|LINK
Well, the easiest and most direct way to do that would be use SQL Server Management Studio. Right click the database > Tasks > Generate Scripts.
Choose your options such as exporting tables, stored procs, and users. Then set your advanced options to export to script: schema only, data only, or both.
Here is a TechNet article that explains the process in detail:
Jul 14, 2017 07:07 AM|Deepak Panchal|LINK
below piece of code may work for you.
ECHO Generating code for %DatabaseFileName%
ECHO Generating create script 'CreateDatabaseSchema.sql'
"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\SqlPubWiz.exe" script -C "Data Source=.\SQLEXPRESS;AttachDbFilename=%CD%\%DatabaseFileName%.mdf;Integrated Security=True;User Instance=True" -noschemaqualify -schemaonly -nodropexisting -f CreateDatabaseSchema.sql
To use, just drop in a .bat next to the .mdf, change DbName and run. It will output 'CreateDatabaseSchema.sql containing create script for all of the tables and stored procs in the database.
Useful Batch File For Generating SQL Create Script from .mdf
Jul 14, 2017 11:59 AM|JohnsonWelch|LINK
Thanks for your valuable solutions, i have converted my .mdf database to .sql format from here: http://www.kodyaz.com/articles/sql-server-script-data-with-generate-script-wizard.aspx ,
Also I got a very helpful SQL database repair tool which has the direct option to export MDF file to .sql script.