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

前端 未结 23 1810
难免孤独
难免孤独 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:02

    Microsoft should advertise this functionality of SSMS 2008. The feature you are looking for is built into the Generate Script utility, but the functionality is turned off by default and must be enabled when scripting a table.

    This is a quick run through to generate the INSERT statements for all of the data in your table, using no scripts or add-ins to SQL Management Studio 2008:

    1. Right-click on the database and go to Tasks > Generate Scripts.
    2. Select the tables (or objects) that you want to generate the script against.
    3. Go to Set scripting options tab and click on the Advanced button.
    4. In the General category, go to Type of data to script
    5. There are 3 options: Schema Only, Data Only, and Schema and Data. Select the appropriate option and click on OK.

    You will then get the CREATE TABLE statement and all of the INSERT statements for the data straight out of SSMS.

提交回复
热议问题