How to create a MS SQL script that (re)creates table data
For automated testing we need test data. The test data must be (re)creatable at any time.
One way is to export the contents of a database table to an SQL script (for remembering the data) and running that script later for (re)creating the data.
Step | Description |
---|---|
1 | Open SQL management studio and select your database |
2 | Use context menu "Tasks/Generate Scripts..." Next... |
3 | "Select specific database objects", e.g. "dbo.WorkflowTemplates" Next... |
4 | "Save to new query window" and click "Advanced" Set "Types of data to script" to "Data only" Next... Next... |
5 | Optionally you want to clean the table before inserting? Then insert a DELETE statement: Finished! You can save your SQL script to a file and use it to (re)create the table contents. |