0

We have a customer that uses a 3rd party system running on SQL Server 2014. I downloaded a copy of the underlying database in .bak format from the 3rd party, which has about 1500 tables and no data. The customer uses a cut-down version of this schema with about 150 of the tables, deleting the ones they don't use.

Somehow they also managed to delete all the indexes... sigh. They have sent me a .bak to do some reporting queries on, but the performance is making me pull out my hair.

I would like to copy the indexes (and pkeys) from the original "pattern" database to the customer's copy. I have seen an excellent solution on how to do this with two identical DBs, but using these leaves me with 1400 names that don't exist, and this causes problems in MSSQLAdmin. Can anyone offer a modification that does not assume the "child" DB has every table and only CREATEs on those that exist?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98
  • The easiest solution might be to download a comparison tool, like ApexSQL, and sync them that way. It appears that Apex's SQL Code Compare is free: https://www.apexsql.com/sql-tools-compare.aspx – critical_error Jul 28 '20 at 21:08
  • Seems quite easy to adjust the code in the linked question to filter out everything not belonging to a list of tables – Martin Smith Jul 28 '20 at 21:12

1 Answers1

0

in case you are using the accepted answer of the question you have mentioned :

WHILE (@@FETCH_STATUS = 0)
BEGIN
    DECLARE @IXSQL NVARCHAR(4000) SET @IXSQL = 'IF OBJECT_ID(''' + @IxTable + ''') IS NOT NULL BEGIN ' --create index if table exists

    SET @IXSQL = @IXSQL + 'CREATE '
    ..............
    
    SET @IXSQL = @IXSQL + ') END'
    -- Print out the CREATE statement for the index
    .................
lptr
  • 1
  • 2
  • 6
  • 16