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

前端 未结 23 1424
难免孤独
难免孤独 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 09:56

    This can be done using Visual Studio too (at least in version 2013 onwards).

    In VS 2013 it is also possible to filter the list of rows the inserts statement are based on, this is something not possible in SSMS as for as I know.

    Perform the following steps:

    • Open the "SQL Server Object Explorer" window (menu: /View/SQL Server Object Explorer)
    • Open / expand the database and its tables
    • Right click on the table and choose "View data" from context menu
    • This will display the data in the main area
    • Optional step: Click on the filter icon "Sort and filter data set" (the fourth icon from the left on the row above the result) and apply some filter to one or more columns
    • Click on the "Script" or "Script to File" icons (the icons on the right of the top row, they look like little sheets of paper)

    This will create the (conditional) insert statements for the selected table to the active window or file.


    The "Filter" and "Script" buttons Visual Studio 2013:

提交回复
热议问题