Sometimes I need to generate insert statement, taking data from a starting database. Suppose you need to create sql installation scripts to create a database from scratch, quite often you need also to insert some initial data into some tables.
Sql server management studio does not provide a simple way to take a table and script all its content into INSERT statement, but a simple solution can be found here. This solution is really simple, it creates a stored into the database that can be used to generate data Es.
exec dbo.insertgenerator MyTableName
And this produces
INSERT DeviceType(IdDeviceType,Description) VALUES('0A2D5544-ACEE-DD11-A239-0050569F32EE','aaa') INSERT DeviceType(IdDeviceType,Description) VALUES('10B8DBAD-42D6-46E5-B787-531CEEFF7526','bbb') INSERT DeviceType(IdDeviceType,Description) VALUES('42BDCDBE-B384-4323-8F1E-CB9367A65075','ccc')
This is really what I need, great script.
alk.
Tags: Sql Server






Leave a Reply