• The sys.index_columns view is utilized because it gives me the ability to join to the key_constraints view to see if the identity column is a primary key or not. This important due to the procedure parameters I accept.

    This procedure builds out a query, that when executed (which the procedure does), the results will generate the INSERT script. Based on the parameters entered it will either include the existing IDENTITY values or it will leave them out of the INSERT script. If excluded, new IDENTITY values will be generated in the destination table upon execution.

    The cursor in the procedure loops through each field in a table analyzing the field data type to determine how the select statement needs to be built out. Based on the parameters it could be built out with NOT EXISTS statements so duplicate data is not entered or it will script out just the INSERT statement.