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 2005 Forums
 Transact-SQL (2005)
 create insert data scripts

Author  Topic 

zion99
Posting Yak Master

141 Posts

Posted - 2008-11-12 : 15:01:16
Hi,

From the available data in a table, is it possible to create insert data scripts for all the rows?

there is an export data functionality available in sql 2005 but i want to give the generated scripts to another person who can just run these scripts & have the data populated in his DB.

safderalimd
Starting Member

32 Posts

Posted - 2008-11-12 : 15:55:47
Here is how you do it..........

create table #temp(col1 int, col2 varchar(5))

insert into #temp values(1, 'emp')
insert into #temp values(1, 'cons')

select 'insert into new_table_name values(' + convert(varchar(5),col1) + ','+''''+col2+''')' from #temp

Copy result set from above slect into seperate file and use it as DML script

insert into new_table_name values(1,'emp')
insert into new_table_name values(1,'cons')
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-12 : 17:01:37
you can also use the SSMS Tools Pack add-in in my signature. You can generate insert scripts for one or more tables or for the entore database.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

zion99
Posting Yak Master

141 Posts

Posted - 2008-11-13 : 05:19:33
quote:
Originally posted by safderalimd

Here is how you do it..........

create table #temp(col1 int, col2 varchar(5))

insert into #temp values(1, 'emp')
insert into #temp values(1, 'cons')

select 'insert into new_table_name values(' + convert(varchar(5),col1) + ','+''''+col2+''')' from #temp

Copy result set from above slect into seperate file and use it as DML script

insert into new_table_name values(1,'emp')
insert into new_table_name values(1,'cons')


thanks, but even in this scenario, i still need to manually write insert query for the temp table which i dont want to do.
Go to Top of Page
   

- Advertisement -