Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Generate instert script for data with a twist

Author  Topic 

dkekesi
Starting Member

38 Posts

Posted - 2012-12-12 : 04:48:58
Hi All,

I need to generate data insert scripts for tables in a database but only for tables whose name begin with 'Enum'. I have hundreds of tables full of data, but only about a dozen Enum tables that contain static data, hence I want to filter for the name.

Any type of solution is OK with me using CLR, TSQL, C#.

Thanks a lot in advance.

Best Regards,
Daniel

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-12-12 : 05:04:41
This is an sp which takes a table name and creates insert statements for the data.
http://www.nigelrivett.net/SQLTsql/sp_CreateDataLoadScript.html
It's very old so may need some tweaking for current versions.


Create a temp table and populate it with the names of tables you require.
Loop through that calling the above sp for each table.
You can insert the output of the sp into a temp table if you want to concatenate all the rows.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dkekesi
Starting Member

38 Posts

Posted - 2012-12-12 : 12:36:36
quote:
Originally posted by nigelrivett
This is an sp which takes a table name and creates insert statements for the data.
http://www.nigelrivett.net/SQLTsql/sp_CreateDataLoadScript.html
It's very old so may need some tweaking for current versions.


Thanks for the help. I ended up using this script here:
http://stackoverflow.com/questions/11001828/restore-to-remote-database-from-my-local-machine
It has a lot of features and handles most data types really well.
Thanks for your time, anyway.

Best Regards,
Daniel
Go to Top of Page
   

- Advertisement -