I need to find a way to generate insert select scripts for a set of tables. The Generate Scripts Task
in SSMS 2008 seems to generate insert values statements. I could just generate them using some of the system views but would prefer to functionality for this already in SSMS
Thanks
What do you want to do? Generate script for Insert or Select? Right click on the table choose 'Script table as' and choose what you want to do
In Object Explorer, pick your database, use Tasks > Generate Scripts..
and then click on the Advanced Options
button:
In the dialog that comes up, you can pick what to script - schema only, data only or schema and data:
You could use this script:
--assuming only the db instance differs
declare @otherDB varchar(100) = 'instanceB'
declare @thisDB varchar(100) = db_name()
select
'INSERT INTO ' + @otherDB + '.' + s.name + '.' + t.name +
' SELECT * FROM ' + @thisDB + '.' + s.name + '.' + t.name
from sys.tables t
inner join sys.schemas s on s.schema_id = t.schema_id
where t.is_ms_shipped = 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.