Do you need to generate a SQL script (a text file of SQL commands in an sql file) from a database or database table in SQL Server? You could do this with SQL Server Management Studio (SSMS). There is Wizard that does this for you. Why would you do this? Perhaps you are making a backup of your database. Perhaps you want to migrate the database of some tables to another database.
How do you do this? First, open up SSMS. Find your database under the Databases folder on the left side. Right-click than select Tasks, Generate Scripts. A window appears. Let’s keep this example simple and only generate a script for a single table in the database. Select Specific Database Objects. Click Next. There are four ways to save the script: notebook, script file, clipboard and a new query window. Let’s pick the file, but before going on we’ll click the Advanced button. In the general options choose the Types of data to script. Also choose Schema and data if you want to create the table and load it with data.