Data Collection: Sharing SQL Server tables via Scripting

How to gather SQL Server tables via Scripting?

In some scenarios, troubleshooting database issues might require a lot of time. In rare scenarios, support engineer might require specific tables. 

Important note: Make sure the shared data does not contain sensitive information or anonymize data before sending the file.

This is useful when fewer tables with their data needs to be shared. For larger data transfer or full db transfer, the backup tools are more suitable. 

1. Right-click on the database and select Tasks > Generate Scripts


2. On the Choose Objects page, select ‘Select specific database objects’ and expand Tables

3. Select all the needed tables and click Next

4. On the Set Scripting Options page, select ‘Save to file’, Files to generate: Single file and File name: path where the current user has write access and click Advanced


5. On Advanced Scripting Options new window, make sure to choose for Types of data to script ‘Schema and data’ and press OK


6. Back on the Set Scripting Options page, select Next

7. On the Summary page review your selections and select Next

8. In the file selected on point 4, script.sql file will be generated