Sql-server – SQL Server Propagation

sql serversql server 2014

I am working in a SQL Server 2014 environment where there are multiple databases where the table structure (column names, data types, sizes) matches. However, the indexes do not necessarily match. For instance one database might have a clustered index on table X, but the next database does not, there may be clustered indexes in one and not in the other, non-clustered indexes may exist in one place where all columns are part of the index key columns while other cases have a mix with included columns, etc.

What I am in need of is a script which will allow me to level set indexes, without removing indexes which exist on the "target" database but not in the "template", while minimizing duplicate and overlapping indexes. In lieu of such a script, some suggestions or guidance in creating one would be a viable option.

Thanks!

Best Answer

Use Visual Studio Sql Server Data Tools. It has a schema compare tool that you can use to view differences between any two databases. I have used this tool to do things very similar to what you are asking.

Instructions for Using the Schema Compare Tool General Instructions are

  1. Create Database Project

  2. Connect Databases to Project

  3. Click "Schema Compare" in SQL Menu

  4. Select Source and Target Database

  5. Hit Compare Button

  6. Select What you want to keep/get rid off

  7. Click on Generate Script