sql - Identify blank tables in a database and insert data from another table on a different database -


actual scenario: have duplicate database , want know in tables data has not been moved original database. want populate duplicate database tables original.

i achieved partial solution (i.e finding empty tables) writing following script:

select     dbdupl.[dbo].sysobjects.name, dbdupl.[dbo].sysindexes.rows     dbdupl.[dbo].sysobjects     inner join dbdupl.[dbo].sysindexes     on dbdupl.[dbo].sysobjects.id = dct_source_qa.[dbo].sysindexes.id     type = 'u'     , dbdupl.[dbo].sysindexes.indid < 2 , rows= '0'      except  select     dborig.[dbo].sysobjects.name, dborig.[dbo].sysindexes.rows     dborig.[dbo].sysobjects     inner join dborig.[dbo].sysindexes      on dborig.[dbo].sysobjects.id = dborig.[dbo].sysindexes.id     type = 'u'     , dborig.[dbo].sysindexes.indid < 2 , rows= '0' 

now want populate data in tables empty. there single query both things i.e (1).finding out tables left populated , (2). populate data dborig dbdupl. have achieved (1) above script , don't want insert data manually.

do want exact copy of database? why not backup of main 1 , restore different name?

if not possible, can use ssis move data or like:

insert destdb.dbo.mytable select * sourcedb.dbo.mytable 

you can use script loop through empty tables , run dynamic sql execute command above


Comments