What is the best way to auto-generate INSERT statements for a SQL Server table?

前端 未结 23 1786
难免孤独
难免孤独 2020-11-22 09:47

We are writing a new application, and while testing, we will need a bunch of dummy data. I\'ve added that data by using MS Access to dump excel files into the relevant table

23条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 10:04

    As mentioned by @Mike Ritacco but updated for SSMS 2008 R2

    1. Right click on the database name
    2. Choose Tasks > Generate scripts
    3. Depending on your settings the intro page may show or not
    4. Choose 'Select specific database objects',
    5. Expand the tree view and check the relevant tables
    6. Click Next
    7. Click Advanced
    8. Under General section, choose the appropriate option for 'Types of data to script'
    9. Complete the wizard

    You will then get all of the INSERT statements for the data straight out of SSMS.

    EDIT 2016-10-25 SQL Server 2016/SSMS 13.0.15900.1

    1. Right click on the database name

    2. Choose Tasks > Generate scripts

    3. Depending on your settings the intro page may show or not

    4. Choose 'Select specific database objects',

    5. Expand the tree view and check the relevant tables

    6. Click Next

    7. Click Advanced

    8. Under General section, choose the appropriate option for 'Types of data to script'

    9. Click OK

    10. Pick whether you want the output to go to a new query, the clipboard or a file

    11. Click Next twice

    12. Your script is prepared in accordance with the settings you picked above

    13. Click Finish

提交回复
热议问题