SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Insert Script Generator

By Linson Daniel,

This stored procedure basically takes the data present in the tables and creates the insert script for the particular table taking care of the datatypes. However datatypes like image have not been handled here. But it could be added on.

This stored procedure has an optional parameter wherin the user can enter the list of table names seperated by commas. Otherwise it could be run without any parameters which in turn would script for all the tables present in that particular database.

The advantages of this stored procedure are

  • It takes of almost all datatypes while insert script generation
  • Script for specific tables can created or for the entire tables in the database
  • It also handles the identity columns wherein the identity columns will not appear in the insert script generated.

The disadvantages of this stored procedure or improvement areas would be:

Well I cant think of any ...(joking).ofcourse there are and it would be

  • It is kinda like an sql developer's nightmare with lots of cursors and dynamic query execution.
  • The Datatype uniqueidentifier here is handled such that the new ids are inserted and not the one that was present in the tables.



There are more better ways to do the same thing and lots of improvements could be added on to it. So please do contribute with your suggestions.




Total article views: 2521 | Views in the last 30 days: 1
Related Articles

Insert Generator - Stored Procedure

Stored procedure to generate an insert script for a table.


Insert Update Stored Procedure for a table

Generic Script for Insert Update Stored Procedures


Scripting Stored Procedures

Scripting Stored Procedures


Dynamic creation of Insert, Update, Delete Stored procedures

Automates the creation of INSERT, UPDATE & DELETE stored procedure of a table


stored procedure vs individual insert statements

stored procedure vs individual insert statements