How can I compare the schema of two databases?How can I find variations in database schemas?How to find out...

What happens when the last remaining players refuse to kill each other?

Do error bars on probabilities have any meaning?

Why don't hotels offer (at least) 1 kitchen bookable by any guest?

Is it appropriate to give a culturally-traditional gift to a female coworker?

How can I ensure that advanced technology remains in the hands of the superhero community?

Negotiating 1-year delay to my Assistant Professor Offer

Why does the current not skip resistors R3 and R5 when R6 and R4 have no resistance?

What is the Guild Die for?

GPL - Is it required to post source code to the Public - when is a software released?

Found a major flaw in paper from home university – to which I would like to return

Was Opportunity's last message to Earth "My battery is low and it's getting dark"?

Is 'bad luck' with former employees a red flag?

Can you make a Spell Glyph of a spell that has the potential to target more than one creature?

Bitcoin automatically diverted to bech32 address

How do I figure out this song by ear if I'm a complete beginner?

Would Refreshing a Sandbox Wipe Out Certain Metadata?

Reverse the order of file matching as arguments

How should I ship cards?

If an area is covered in both Ball Bearings and Caltrops, does the creature need to move at half speed or quarter speed to avoid both their effects?

I'm struggling to say 'struggle'

Contribution form

Run a command that requires sudo after a time has passed

Does an increasing sequence of reals converge if the difference of consecutive terms approaches zero?

Copy the content of an environment



How can I compare the schema of two databases?


How can I find variations in database schemas?How to find out what caused a schema change?Two databases of same size, backups sizes are very differentPostgreSQL: schema diff/patch toolWhat are some databases that are schema-full but not relationalSSDT Schema Compare fails when comparing my DB Project to my Azure ServerCompare order of columns between two databasesCompare and auto fix conflicts between two SQL Server databases with T-sqlHow do I compare Schemas for Multiple Databases to a True Copy?How can to make a new user see table in existing schema













14















Is there a way to find the differences in two SQL Server databases (schema only). One is local and the second is at a customer's site. We are experiencing problems with crystal reports running some reports and some code not executing and it would appear that the schemas don't match.



Can I run the same command on both databases and compare the results to tell where the differences are?










share|improve this question

























  • This question on SO has some good suggestions.

    – LowlyDBA
    Mar 13 '15 at 20:55
















14















Is there a way to find the differences in two SQL Server databases (schema only). One is local and the second is at a customer's site. We are experiencing problems with crystal reports running some reports and some code not executing and it would appear that the schemas don't match.



Can I run the same command on both databases and compare the results to tell where the differences are?










share|improve this question

























  • This question on SO has some good suggestions.

    – LowlyDBA
    Mar 13 '15 at 20:55














14












14








14


2






Is there a way to find the differences in two SQL Server databases (schema only). One is local and the second is at a customer's site. We are experiencing problems with crystal reports running some reports and some code not executing and it would appear that the schemas don't match.



Can I run the same command on both databases and compare the results to tell where the differences are?










share|improve this question
















Is there a way to find the differences in two SQL Server databases (schema only). One is local and the second is at a customer's site. We are experiencing problems with crystal reports running some reports and some code not executing and it would appear that the schemas don't match.



Can I run the same command on both databases and compare the results to tell where the differences are?







sql-server sql-server-2008-r2 schema






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 '18 at 10:10









Michael Green

14.7k83060




14.7k83060










asked Mar 13 '15 at 20:50









user1571430user1571430

71113




71113













  • This question on SO has some good suggestions.

    – LowlyDBA
    Mar 13 '15 at 20:55



















  • This question on SO has some good suggestions.

    – LowlyDBA
    Mar 13 '15 at 20:55

















This question on SO has some good suggestions.

– LowlyDBA
Mar 13 '15 at 20:55





This question on SO has some good suggestions.

– LowlyDBA
Mar 13 '15 at 20:55










15 Answers
15






active

oldest

votes


















10














If you cannot use one of the many tools out there because of connectivity problems and want an "offline" compare, you can use SSMS to generate scripts for all database objects by right clicking on the database and using the "Tasks.../Generate Scripts" function, and make sure you select to create one file per object.



When you have done that for both databases, get the two sets of scripts onto a local machine in two separate folders and use WinMerge (or similar) to compare the two.






share|improve this answer































    7














    Another option is to use SQL Server Data Tools (SSDT), an extension of Visual Studio. You can extract your database schema as a .dacpac file and compare that with another .dacpac file or an existing database. SSDT is included with SQL Server 2012 client tools, making it pretty accessible. You can find the full instructions of how to run the compare on the MSDN site.






    share|improve this answer

































      5














      After struggling with an easy way to do this same task - see what's changed between 2 models, I wrote the following SQL Script that will compare two schemas to determine new and deleted columns



      set nocount on;
      -- Set the two variables newmodel and oldmodel to the appropriate database names and execute the script

      declare @newmodel varchar(50), @oldmodel varchar(50);

      Set @newmodel = '[NewModel to Compare]';
      set @oldmodel = '[OldModel to Compare]';


      Declare @Temp table (TABLE_SCHEMA varchar(40), TABLE_NAME varchar(40), COLUMN_NAME varchar(50), ORDINAL_POSITION int, IS_NULLABLE varchar(5), NullChange varchar(5), Comment varchar(50));

      Declare @script varchar(5000);


      set @script = '
      Select nc.TABLE_SCHEMA, nc.TABLE_NAME, nc.COLUMN_NAME, nc.ORDINAL_POSITION, nc.IS_NULLABLE, IIF(nc.IS_NULLABLE <> oc.IS_NULLABLE, ''Yes'', ''No''),
      IIF(oc.COLUMN_NAME IS NULL, convert(varchar(20), ''ADDED COLUMN''), convert(varchar(20), ''--'')) as Comment
      from {NEW}.INFORMATION_SCHEMA.COLUMNS nc
      LEFT join {OLD}.INFORMATION_SCHEMA.COLUMNS oc
      on nc.TABLE_NAME = oc.TABLE_NAME and nc.COLUMN_NAME = oc.COLUMN_NAME
      UNION ALL
      Select oc.TABLE_SCHEMA, oc.TABLE_NAME, oc.COLUMN_NAME, oc.ORDINAL_POSITION, oc.IS_NULLABLE, ''No'', ''DELETED COLUMN'' as Comment
      from {OLD}.INFORMATION_SCHEMA.COLUMNS oc
      where CONCAT(oc.TABLE_NAME, ''.'', oc.COLUMN_NAME)
      not in (Select CONCAT(TABLE_NAME, ''.'', COLUMN_NAME) from {NEW}.INFORMATION_SCHEMA.COLUMNS)
      ';


      Set @script = replace(@script, '{OLD}', @oldmodel);
      Set @script = replace(@script, '{NEW}', @newmodel);

      --print @script

      Insert into @Temp
      exec(@script);

      Select * from @Temp where Comment <> '--'
      order by TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME;
      go





      share|improve this answer


























      • For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

        – Mir
        Oct 4 '17 at 20:29



















      2














      If you need to compare more than one database file you could script SQLPackage.exe.



      I don't have working code for you but you could look at the SQLPackage.exe documentation for some inspiration.



      You would extract your master database to a dacpac file and then compare the dacpac file to the rest of your databases. The result of the comparison could either be a xml report of the changes or a .sql file you can run to synchronize the databases.



      Something like this:



      sqlpackage.exe /a:Extract /scs:Server=MyLaptopSQL2014;Database=Test; /tf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac  


      and then



      sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test1 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest1.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True 
      sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test2 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest2.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True


      You can have a look at this article or this one for sample code.






      share|improve this answer































        1














        Do a search for "SQL Server Compare" and you'll find lots of tools. The one we use at my job is Red Gate SQLCompare. It has a 14 day trial. But since you are talking about two different environments I don't think that would work for you, unless the client sends you a backup of their DB. The other option is to write queries against the system tables (like sys.indexes, sys.tables, etc).






        share|improve this answer
























        • SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

          – Mark Sinkinson
          Mar 14 '15 at 7:47



















        1














        The easiest way is to use an automated tool built for this purpose, but if you don't have access to one, you can get all of the basic information that you need from the INFORMATION_SCHEMA views.



        Using the metadata in INFORMATION_SCHEMA is probably an easier option than generating DDL scripts and doing a source compare because you have much more control over how the data is presented. You can't really control the order in which generated scripts will present the objects in a database. Also, the scripts contain a bunch of text that may be implementation dependent by default and may cause a lot of mismatch "noise" when what you probably really need to focus on is a missing table, view or column, or possibly a column data type or size mismatch.



        Write a query (or queries) to get the information that matters to your code from the INFORMATION_SCHEMA views and run it on each SQL Server from SSMS. You can then either dump the results to a file and use a text file compare tool (even MS Word) or you can dump the results to tables and run SQL queries to find mismatches.






        share|improve this answer

































          1














          I am including this answer for the sake of a new question that was marked as a duplicate.



          I once had to compare two production databases and find any schema differences between them. The only items of interest were tables that had been added or dropped and columns that had been added, removed, or altered. I no longer have the SQL scripts I developed, but what follows is the general strategy. And the database was not SQL Server, but I think the same strategy applies.



          First, I created what can best be described as a metadatabase. The user tables of this database contained data descriptions copied from the system tables of the production databases. Things like Table Name, Column Name, Data Type and Precision. There was one more item, Database Name, that did not exist in either of the production databases.



          Next, I developed scripts that coupled selects from the system tables of the production databases with inserts into the user tables of the metadatabase.



          Finally, I developed queries to find tables that existed in one database but not the other, and columns from tables in both database that were only in one database, and columns with inconsistent definitions between the two databases.



          Out of about 100 tables and 600 columns, I found a handful of inconsistencies, and one column that was defined as a floating point in one database and an integer in the other. That last one turned out to be a godsend, because it unearthed a problem that had been plaguing one of the databases for years.



          The model for the metadatabase was suggested by the system tables in question. The queries were not hard to construct, revolving mostly around group by and having count(database name) = 1.



          In your case, with 700 production databases, you might want to automate the first two steps more than I did with just two databases to compare. But the idea is similar.






          share|improve this answer

































            1














            I had this exact same question and I believe that the Microsoft SQL Server Management Studio (SSMS) has a much easier/simpler solution than anything I saw here. I have a production site with MS SQL Server Express and soon to be several more where I don't want to have to install VisualStudio or other applications other than SSMS.



            So within SSMS, right click on the database to get the schema for. Select Tasks > Generate Scripts... to open a wizard to script the schema and configuration for the entire database (or selected objects if you want). I kept all the default options except the path/filename, but the tool has a plethora of options. The wizard created one SQL which I copied via OneDrive back to my PC. I then used Notepad++ to compare the SQL to a file generated in the same way against my SIT database. You have to filter out hits from the date/time in comments, but otherwise it is a great comparison of the two databases.



            Presto! Writing this up was significantly harder than doing the actual compare.






            share|improve this answer

































              0














              A great tool I use (although not updated in a while still works) is AdeptSqlDiff



              Does both schema compares as well as data comparisons. Just like RedGate there is a cost but also a 30 day trial. And the price is pretty reasonable.






              share|improve this answer































                0














                Maybe this free script https://github.com/dlevsha/compalex can help you. It support Microsoft SQL Server.




                Compalex is a free lightweight script to compare two database schemas. It
                supports MySQL, MS SQL Server and PostgreSQL.




                You can try demo here



                http://demo.compalex.net/






                share|improve this answer































                  0














                  There are many third party tools out there which will do schema and data compare, and synchronization. Two tools you can use are the ones my team and I have developed, xSQL Schema Compare for schema comparisons and xSQL Data Compare for data comparisons between objects with the same schema. Hope this helps!


                  Disclaimer: I'm affiliated to xSQL






                  share|improve this answer

































                    0














                    There is a lot of tools on the market which you might use to get the job done. My company is using ApexSQL Diff for both comparison and sync because it is free for Azure, but you can’t go wrong with either Devart or Redgate tools.






                    share|improve this answer































                      0














                      I'm a fan of SQL DBDiff, which is an open source tool you can use to compare tables, views, functions, users, etc. of two instances of SQL Server databases and generate a change script between the source and destination databases.






                      share|improve this answer































                        0














                        Check this out:



                        SELECT TABLE_SCHEMA ,
                        TABLE_NAME ,
                        COLUMN_NAME ,
                        ORDINAL_POSITION ,
                        COLUMN_DEFAULT ,
                        DATA_TYPE ,
                        CHARACTER_MAXIMUM_LENGTH ,
                        NUMERIC_PRECISION ,
                        NUMERIC_PRECISION_RADIX ,
                        NUMERIC_SCALE ,
                        DATETIME_PRECISION
                        FROM INFORMATION_SCHEMA.COLUMNS
                        where TABLE_SCHEMA in ('dbo','meta')
                        and table_name in (select name from sys.tables)
                        order by TABLE_SCHEMA , TABLE_NAME ,ORDINAL_POSITION


                        enter image description here






                        share|improve this answer



















                        • 3





                          This really needs to be about comparing, not just getting the schema

                          – Mark Sinkinson
                          Mar 7 '18 at 7:18











                        • I'll just leave it here encase it helps others. It helped me

                          – Jeremy Thompson
                          Mar 8 '18 at 10:49



















                        0














                        I use this free (and open source) tool: OpenDBDiff






                        share|improve this answer























                          Your Answer








                          StackExchange.ready(function() {
                          var channelOptions = {
                          tags: "".split(" "),
                          id: "182"
                          };
                          initTagRenderer("".split(" "), "".split(" "), channelOptions);

                          StackExchange.using("externalEditor", function() {
                          // Have to fire editor after snippets, if snippets enabled
                          if (StackExchange.settings.snippets.snippetsEnabled) {
                          StackExchange.using("snippets", function() {
                          createEditor();
                          });
                          }
                          else {
                          createEditor();
                          }
                          });

                          function createEditor() {
                          StackExchange.prepareEditor({
                          heartbeatType: 'answer',
                          autoActivateHeartbeat: false,
                          convertImagesToLinks: false,
                          noModals: true,
                          showLowRepImageUploadWarning: true,
                          reputationToPostImages: null,
                          bindNavPrevention: true,
                          postfix: "",
                          imageUploader: {
                          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                          allowUrls: true
                          },
                          onDemand: true,
                          discardSelector: ".discard-answer"
                          ,immediatelyShowMarkdownHelp:true
                          });


                          }
                          });














                          draft saved

                          draft discarded


















                          StackExchange.ready(
                          function () {
                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f95236%2fhow-can-i-compare-the-schema-of-two-databases%23new-answer', 'question_page');
                          }
                          );

                          Post as a guest















                          Required, but never shown

























                          15 Answers
                          15






                          active

                          oldest

                          votes








                          15 Answers
                          15






                          active

                          oldest

                          votes









                          active

                          oldest

                          votes






                          active

                          oldest

                          votes









                          10














                          If you cannot use one of the many tools out there because of connectivity problems and want an "offline" compare, you can use SSMS to generate scripts for all database objects by right clicking on the database and using the "Tasks.../Generate Scripts" function, and make sure you select to create one file per object.



                          When you have done that for both databases, get the two sets of scripts onto a local machine in two separate folders and use WinMerge (or similar) to compare the two.






                          share|improve this answer




























                            10














                            If you cannot use one of the many tools out there because of connectivity problems and want an "offline" compare, you can use SSMS to generate scripts for all database objects by right clicking on the database and using the "Tasks.../Generate Scripts" function, and make sure you select to create one file per object.



                            When you have done that for both databases, get the two sets of scripts onto a local machine in two separate folders and use WinMerge (or similar) to compare the two.






                            share|improve this answer


























                              10












                              10








                              10







                              If you cannot use one of the many tools out there because of connectivity problems and want an "offline" compare, you can use SSMS to generate scripts for all database objects by right clicking on the database and using the "Tasks.../Generate Scripts" function, and make sure you select to create one file per object.



                              When you have done that for both databases, get the two sets of scripts onto a local machine in two separate folders and use WinMerge (or similar) to compare the two.






                              share|improve this answer













                              If you cannot use one of the many tools out there because of connectivity problems and want an "offline" compare, you can use SSMS to generate scripts for all database objects by right clicking on the database and using the "Tasks.../Generate Scripts" function, and make sure you select to create one file per object.



                              When you have done that for both databases, get the two sets of scripts onto a local machine in two separate folders and use WinMerge (or similar) to compare the two.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 14 '15 at 0:33









                              Mister MagooMister Magoo

                              2,463916




                              2,463916

























                                  7














                                  Another option is to use SQL Server Data Tools (SSDT), an extension of Visual Studio. You can extract your database schema as a .dacpac file and compare that with another .dacpac file or an existing database. SSDT is included with SQL Server 2012 client tools, making it pretty accessible. You can find the full instructions of how to run the compare on the MSDN site.






                                  share|improve this answer






























                                    7














                                    Another option is to use SQL Server Data Tools (SSDT), an extension of Visual Studio. You can extract your database schema as a .dacpac file and compare that with another .dacpac file or an existing database. SSDT is included with SQL Server 2012 client tools, making it pretty accessible. You can find the full instructions of how to run the compare on the MSDN site.






                                    share|improve this answer




























                                      7












                                      7








                                      7







                                      Another option is to use SQL Server Data Tools (SSDT), an extension of Visual Studio. You can extract your database schema as a .dacpac file and compare that with another .dacpac file or an existing database. SSDT is included with SQL Server 2012 client tools, making it pretty accessible. You can find the full instructions of how to run the compare on the MSDN site.






                                      share|improve this answer















                                      Another option is to use SQL Server Data Tools (SSDT), an extension of Visual Studio. You can extract your database schema as a .dacpac file and compare that with another .dacpac file or an existing database. SSDT is included with SQL Server 2012 client tools, making it pretty accessible. You can find the full instructions of how to run the compare on the MSDN site.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 15 '15 at 15:40

























                                      answered Mar 15 '15 at 15:30









                                      Mike FalMike Fal

                                      10.5k13253




                                      10.5k13253























                                          5














                                          After struggling with an easy way to do this same task - see what's changed between 2 models, I wrote the following SQL Script that will compare two schemas to determine new and deleted columns



                                          set nocount on;
                                          -- Set the two variables newmodel and oldmodel to the appropriate database names and execute the script

                                          declare @newmodel varchar(50), @oldmodel varchar(50);

                                          Set @newmodel = '[NewModel to Compare]';
                                          set @oldmodel = '[OldModel to Compare]';


                                          Declare @Temp table (TABLE_SCHEMA varchar(40), TABLE_NAME varchar(40), COLUMN_NAME varchar(50), ORDINAL_POSITION int, IS_NULLABLE varchar(5), NullChange varchar(5), Comment varchar(50));

                                          Declare @script varchar(5000);


                                          set @script = '
                                          Select nc.TABLE_SCHEMA, nc.TABLE_NAME, nc.COLUMN_NAME, nc.ORDINAL_POSITION, nc.IS_NULLABLE, IIF(nc.IS_NULLABLE <> oc.IS_NULLABLE, ''Yes'', ''No''),
                                          IIF(oc.COLUMN_NAME IS NULL, convert(varchar(20), ''ADDED COLUMN''), convert(varchar(20), ''--'')) as Comment
                                          from {NEW}.INFORMATION_SCHEMA.COLUMNS nc
                                          LEFT join {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          on nc.TABLE_NAME = oc.TABLE_NAME and nc.COLUMN_NAME = oc.COLUMN_NAME
                                          UNION ALL
                                          Select oc.TABLE_SCHEMA, oc.TABLE_NAME, oc.COLUMN_NAME, oc.ORDINAL_POSITION, oc.IS_NULLABLE, ''No'', ''DELETED COLUMN'' as Comment
                                          from {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          where CONCAT(oc.TABLE_NAME, ''.'', oc.COLUMN_NAME)
                                          not in (Select CONCAT(TABLE_NAME, ''.'', COLUMN_NAME) from {NEW}.INFORMATION_SCHEMA.COLUMNS)
                                          ';


                                          Set @script = replace(@script, '{OLD}', @oldmodel);
                                          Set @script = replace(@script, '{NEW}', @newmodel);

                                          --print @script

                                          Insert into @Temp
                                          exec(@script);

                                          Select * from @Temp where Comment <> '--'
                                          order by TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME;
                                          go





                                          share|improve this answer


























                                          • For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                            – Mir
                                            Oct 4 '17 at 20:29
















                                          5














                                          After struggling with an easy way to do this same task - see what's changed between 2 models, I wrote the following SQL Script that will compare two schemas to determine new and deleted columns



                                          set nocount on;
                                          -- Set the two variables newmodel and oldmodel to the appropriate database names and execute the script

                                          declare @newmodel varchar(50), @oldmodel varchar(50);

                                          Set @newmodel = '[NewModel to Compare]';
                                          set @oldmodel = '[OldModel to Compare]';


                                          Declare @Temp table (TABLE_SCHEMA varchar(40), TABLE_NAME varchar(40), COLUMN_NAME varchar(50), ORDINAL_POSITION int, IS_NULLABLE varchar(5), NullChange varchar(5), Comment varchar(50));

                                          Declare @script varchar(5000);


                                          set @script = '
                                          Select nc.TABLE_SCHEMA, nc.TABLE_NAME, nc.COLUMN_NAME, nc.ORDINAL_POSITION, nc.IS_NULLABLE, IIF(nc.IS_NULLABLE <> oc.IS_NULLABLE, ''Yes'', ''No''),
                                          IIF(oc.COLUMN_NAME IS NULL, convert(varchar(20), ''ADDED COLUMN''), convert(varchar(20), ''--'')) as Comment
                                          from {NEW}.INFORMATION_SCHEMA.COLUMNS nc
                                          LEFT join {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          on nc.TABLE_NAME = oc.TABLE_NAME and nc.COLUMN_NAME = oc.COLUMN_NAME
                                          UNION ALL
                                          Select oc.TABLE_SCHEMA, oc.TABLE_NAME, oc.COLUMN_NAME, oc.ORDINAL_POSITION, oc.IS_NULLABLE, ''No'', ''DELETED COLUMN'' as Comment
                                          from {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          where CONCAT(oc.TABLE_NAME, ''.'', oc.COLUMN_NAME)
                                          not in (Select CONCAT(TABLE_NAME, ''.'', COLUMN_NAME) from {NEW}.INFORMATION_SCHEMA.COLUMNS)
                                          ';


                                          Set @script = replace(@script, '{OLD}', @oldmodel);
                                          Set @script = replace(@script, '{NEW}', @newmodel);

                                          --print @script

                                          Insert into @Temp
                                          exec(@script);

                                          Select * from @Temp where Comment <> '--'
                                          order by TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME;
                                          go





                                          share|improve this answer


























                                          • For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                            – Mir
                                            Oct 4 '17 at 20:29














                                          5












                                          5








                                          5







                                          After struggling with an easy way to do this same task - see what's changed between 2 models, I wrote the following SQL Script that will compare two schemas to determine new and deleted columns



                                          set nocount on;
                                          -- Set the two variables newmodel and oldmodel to the appropriate database names and execute the script

                                          declare @newmodel varchar(50), @oldmodel varchar(50);

                                          Set @newmodel = '[NewModel to Compare]';
                                          set @oldmodel = '[OldModel to Compare]';


                                          Declare @Temp table (TABLE_SCHEMA varchar(40), TABLE_NAME varchar(40), COLUMN_NAME varchar(50), ORDINAL_POSITION int, IS_NULLABLE varchar(5), NullChange varchar(5), Comment varchar(50));

                                          Declare @script varchar(5000);


                                          set @script = '
                                          Select nc.TABLE_SCHEMA, nc.TABLE_NAME, nc.COLUMN_NAME, nc.ORDINAL_POSITION, nc.IS_NULLABLE, IIF(nc.IS_NULLABLE <> oc.IS_NULLABLE, ''Yes'', ''No''),
                                          IIF(oc.COLUMN_NAME IS NULL, convert(varchar(20), ''ADDED COLUMN''), convert(varchar(20), ''--'')) as Comment
                                          from {NEW}.INFORMATION_SCHEMA.COLUMNS nc
                                          LEFT join {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          on nc.TABLE_NAME = oc.TABLE_NAME and nc.COLUMN_NAME = oc.COLUMN_NAME
                                          UNION ALL
                                          Select oc.TABLE_SCHEMA, oc.TABLE_NAME, oc.COLUMN_NAME, oc.ORDINAL_POSITION, oc.IS_NULLABLE, ''No'', ''DELETED COLUMN'' as Comment
                                          from {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          where CONCAT(oc.TABLE_NAME, ''.'', oc.COLUMN_NAME)
                                          not in (Select CONCAT(TABLE_NAME, ''.'', COLUMN_NAME) from {NEW}.INFORMATION_SCHEMA.COLUMNS)
                                          ';


                                          Set @script = replace(@script, '{OLD}', @oldmodel);
                                          Set @script = replace(@script, '{NEW}', @newmodel);

                                          --print @script

                                          Insert into @Temp
                                          exec(@script);

                                          Select * from @Temp where Comment <> '--'
                                          order by TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME;
                                          go





                                          share|improve this answer















                                          After struggling with an easy way to do this same task - see what's changed between 2 models, I wrote the following SQL Script that will compare two schemas to determine new and deleted columns



                                          set nocount on;
                                          -- Set the two variables newmodel and oldmodel to the appropriate database names and execute the script

                                          declare @newmodel varchar(50), @oldmodel varchar(50);

                                          Set @newmodel = '[NewModel to Compare]';
                                          set @oldmodel = '[OldModel to Compare]';


                                          Declare @Temp table (TABLE_SCHEMA varchar(40), TABLE_NAME varchar(40), COLUMN_NAME varchar(50), ORDINAL_POSITION int, IS_NULLABLE varchar(5), NullChange varchar(5), Comment varchar(50));

                                          Declare @script varchar(5000);


                                          set @script = '
                                          Select nc.TABLE_SCHEMA, nc.TABLE_NAME, nc.COLUMN_NAME, nc.ORDINAL_POSITION, nc.IS_NULLABLE, IIF(nc.IS_NULLABLE <> oc.IS_NULLABLE, ''Yes'', ''No''),
                                          IIF(oc.COLUMN_NAME IS NULL, convert(varchar(20), ''ADDED COLUMN''), convert(varchar(20), ''--'')) as Comment
                                          from {NEW}.INFORMATION_SCHEMA.COLUMNS nc
                                          LEFT join {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          on nc.TABLE_NAME = oc.TABLE_NAME and nc.COLUMN_NAME = oc.COLUMN_NAME
                                          UNION ALL
                                          Select oc.TABLE_SCHEMA, oc.TABLE_NAME, oc.COLUMN_NAME, oc.ORDINAL_POSITION, oc.IS_NULLABLE, ''No'', ''DELETED COLUMN'' as Comment
                                          from {OLD}.INFORMATION_SCHEMA.COLUMNS oc
                                          where CONCAT(oc.TABLE_NAME, ''.'', oc.COLUMN_NAME)
                                          not in (Select CONCAT(TABLE_NAME, ''.'', COLUMN_NAME) from {NEW}.INFORMATION_SCHEMA.COLUMNS)
                                          ';


                                          Set @script = replace(@script, '{OLD}', @oldmodel);
                                          Set @script = replace(@script, '{NEW}', @newmodel);

                                          --print @script

                                          Insert into @Temp
                                          exec(@script);

                                          Select * from @Temp where Comment <> '--'
                                          order by TABLE_NAME, ORDINAL_POSITION, COLUMN_NAME;
                                          go






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Aug 21 '17 at 22:18

























                                          answered Aug 21 '17 at 14:57









                                          John AdamsJohn Adams

                                          5112




                                          5112













                                          • For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                            – Mir
                                            Oct 4 '17 at 20:29



















                                          • For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                            – Mir
                                            Oct 4 '17 at 20:29

















                                          For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                          – Mir
                                          Oct 4 '17 at 20:29





                                          For a quick and dirty solution that doesn't require any extra software, this is great! It's exactly what I needed. Thanks!

                                          – Mir
                                          Oct 4 '17 at 20:29











                                          2














                                          If you need to compare more than one database file you could script SQLPackage.exe.



                                          I don't have working code for you but you could look at the SQLPackage.exe documentation for some inspiration.



                                          You would extract your master database to a dacpac file and then compare the dacpac file to the rest of your databases. The result of the comparison could either be a xml report of the changes or a .sql file you can run to synchronize the databases.



                                          Something like this:



                                          sqlpackage.exe /a:Extract /scs:Server=MyLaptopSQL2014;Database=Test; /tf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac  


                                          and then



                                          sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test1 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest1.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True 
                                          sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test2 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest2.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True


                                          You can have a look at this article or this one for sample code.






                                          share|improve this answer




























                                            2














                                            If you need to compare more than one database file you could script SQLPackage.exe.



                                            I don't have working code for you but you could look at the SQLPackage.exe documentation for some inspiration.



                                            You would extract your master database to a dacpac file and then compare the dacpac file to the rest of your databases. The result of the comparison could either be a xml report of the changes or a .sql file you can run to synchronize the databases.



                                            Something like this:



                                            sqlpackage.exe /a:Extract /scs:Server=MyLaptopSQL2014;Database=Test; /tf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac  


                                            and then



                                            sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test1 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest1.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True 
                                            sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test2 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest2.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True


                                            You can have a look at this article or this one for sample code.






                                            share|improve this answer


























                                              2












                                              2








                                              2







                                              If you need to compare more than one database file you could script SQLPackage.exe.



                                              I don't have working code for you but you could look at the SQLPackage.exe documentation for some inspiration.



                                              You would extract your master database to a dacpac file and then compare the dacpac file to the rest of your databases. The result of the comparison could either be a xml report of the changes or a .sql file you can run to synchronize the databases.



                                              Something like this:



                                              sqlpackage.exe /a:Extract /scs:Server=MyLaptopSQL2014;Database=Test; /tf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac  


                                              and then



                                              sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test1 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest1.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True 
                                              sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test2 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest2.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True


                                              You can have a look at this article or this one for sample code.






                                              share|improve this answer













                                              If you need to compare more than one database file you could script SQLPackage.exe.



                                              I don't have working code for you but you could look at the SQLPackage.exe documentation for some inspiration.



                                              You would extract your master database to a dacpac file and then compare the dacpac file to the rest of your databases. The result of the comparison could either be a xml report of the changes or a .sql file you can run to synchronize the databases.



                                              Something like this:



                                              sqlpackage.exe /a:Extract /scs:Server=MyLaptopSQL2014;Database=Test; /tf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac  


                                              and then



                                              sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test1 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest1.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True 
                                              sqlpackage.exe /a:Script /sf:C:UsersKevin3NFDocumentsSQLScriptsDACPACSTest.dacpac /tsn:MyLaptopSQL2014 /tdn:Test2 /op:C:UsersKevin3NFDocumentsSQLScriptsDACPACSDeltasTest2.sql /p:DropObjectsNotInSource=True /p:DropIndexesNotInSource=True


                                              You can have a look at this article or this one for sample code.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jul 12 '18 at 8:25









                                              Tom VTom V

                                              13.9k74677




                                              13.9k74677























                                                  1














                                                  Do a search for "SQL Server Compare" and you'll find lots of tools. The one we use at my job is Red Gate SQLCompare. It has a 14 day trial. But since you are talking about two different environments I don't think that would work for you, unless the client sends you a backup of their DB. The other option is to write queries against the system tables (like sys.indexes, sys.tables, etc).






                                                  share|improve this answer
























                                                  • SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                    – Mark Sinkinson
                                                    Mar 14 '15 at 7:47
















                                                  1














                                                  Do a search for "SQL Server Compare" and you'll find lots of tools. The one we use at my job is Red Gate SQLCompare. It has a 14 day trial. But since you are talking about two different environments I don't think that would work for you, unless the client sends you a backup of their DB. The other option is to write queries against the system tables (like sys.indexes, sys.tables, etc).






                                                  share|improve this answer
























                                                  • SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                    – Mark Sinkinson
                                                    Mar 14 '15 at 7:47














                                                  1












                                                  1








                                                  1







                                                  Do a search for "SQL Server Compare" and you'll find lots of tools. The one we use at my job is Red Gate SQLCompare. It has a 14 day trial. But since you are talking about two different environments I don't think that would work for you, unless the client sends you a backup of their DB. The other option is to write queries against the system tables (like sys.indexes, sys.tables, etc).






                                                  share|improve this answer













                                                  Do a search for "SQL Server Compare" and you'll find lots of tools. The one we use at my job is Red Gate SQLCompare. It has a 14 day trial. But since you are talking about two different environments I don't think that would work for you, unless the client sends you a backup of their DB. The other option is to write queries against the system tables (like sys.indexes, sys.tables, etc).







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Mar 13 '15 at 20:55









                                                  Chris WoodsChris Woods

                                                  1,146721




                                                  1,146721













                                                  • SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                    – Mark Sinkinson
                                                    Mar 14 '15 at 7:47



















                                                  • SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                    – Mark Sinkinson
                                                    Mar 14 '15 at 7:47

















                                                  SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                  – Mark Sinkinson
                                                  Mar 14 '15 at 7:47





                                                  SQL Compare works fine if you have logins to both servers. You can use a different login to each DB, so the client would have to ensure you had access.

                                                  – Mark Sinkinson
                                                  Mar 14 '15 at 7:47











                                                  1














                                                  The easiest way is to use an automated tool built for this purpose, but if you don't have access to one, you can get all of the basic information that you need from the INFORMATION_SCHEMA views.



                                                  Using the metadata in INFORMATION_SCHEMA is probably an easier option than generating DDL scripts and doing a source compare because you have much more control over how the data is presented. You can't really control the order in which generated scripts will present the objects in a database. Also, the scripts contain a bunch of text that may be implementation dependent by default and may cause a lot of mismatch "noise" when what you probably really need to focus on is a missing table, view or column, or possibly a column data type or size mismatch.



                                                  Write a query (or queries) to get the information that matters to your code from the INFORMATION_SCHEMA views and run it on each SQL Server from SSMS. You can then either dump the results to a file and use a text file compare tool (even MS Word) or you can dump the results to tables and run SQL queries to find mismatches.






                                                  share|improve this answer






























                                                    1














                                                    The easiest way is to use an automated tool built for this purpose, but if you don't have access to one, you can get all of the basic information that you need from the INFORMATION_SCHEMA views.



                                                    Using the metadata in INFORMATION_SCHEMA is probably an easier option than generating DDL scripts and doing a source compare because you have much more control over how the data is presented. You can't really control the order in which generated scripts will present the objects in a database. Also, the scripts contain a bunch of text that may be implementation dependent by default and may cause a lot of mismatch "noise" when what you probably really need to focus on is a missing table, view or column, or possibly a column data type or size mismatch.



                                                    Write a query (or queries) to get the information that matters to your code from the INFORMATION_SCHEMA views and run it on each SQL Server from SSMS. You can then either dump the results to a file and use a text file compare tool (even MS Word) or you can dump the results to tables and run SQL queries to find mismatches.






                                                    share|improve this answer




























                                                      1












                                                      1








                                                      1







                                                      The easiest way is to use an automated tool built for this purpose, but if you don't have access to one, you can get all of the basic information that you need from the INFORMATION_SCHEMA views.



                                                      Using the metadata in INFORMATION_SCHEMA is probably an easier option than generating DDL scripts and doing a source compare because you have much more control over how the data is presented. You can't really control the order in which generated scripts will present the objects in a database. Also, the scripts contain a bunch of text that may be implementation dependent by default and may cause a lot of mismatch "noise" when what you probably really need to focus on is a missing table, view or column, or possibly a column data type or size mismatch.



                                                      Write a query (or queries) to get the information that matters to your code from the INFORMATION_SCHEMA views and run it on each SQL Server from SSMS. You can then either dump the results to a file and use a text file compare tool (even MS Word) or you can dump the results to tables and run SQL queries to find mismatches.






                                                      share|improve this answer















                                                      The easiest way is to use an automated tool built for this purpose, but if you don't have access to one, you can get all of the basic information that you need from the INFORMATION_SCHEMA views.



                                                      Using the metadata in INFORMATION_SCHEMA is probably an easier option than generating DDL scripts and doing a source compare because you have much more control over how the data is presented. You can't really control the order in which generated scripts will present the objects in a database. Also, the scripts contain a bunch of text that may be implementation dependent by default and may cause a lot of mismatch "noise" when what you probably really need to focus on is a missing table, view or column, or possibly a column data type or size mismatch.



                                                      Write a query (or queries) to get the information that matters to your code from the INFORMATION_SCHEMA views and run it on each SQL Server from SSMS. You can then either dump the results to a file and use a text file compare tool (even MS Word) or you can dump the results to tables and run SQL queries to find mismatches.







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Sep 1 '16 at 10:49

























                                                      answered Mar 15 '15 at 15:12









                                                      Joel BrownJoel Brown

                                                      10.4k21837




                                                      10.4k21837























                                                          1














                                                          I am including this answer for the sake of a new question that was marked as a duplicate.



                                                          I once had to compare two production databases and find any schema differences between them. The only items of interest were tables that had been added or dropped and columns that had been added, removed, or altered. I no longer have the SQL scripts I developed, but what follows is the general strategy. And the database was not SQL Server, but I think the same strategy applies.



                                                          First, I created what can best be described as a metadatabase. The user tables of this database contained data descriptions copied from the system tables of the production databases. Things like Table Name, Column Name, Data Type and Precision. There was one more item, Database Name, that did not exist in either of the production databases.



                                                          Next, I developed scripts that coupled selects from the system tables of the production databases with inserts into the user tables of the metadatabase.



                                                          Finally, I developed queries to find tables that existed in one database but not the other, and columns from tables in both database that were only in one database, and columns with inconsistent definitions between the two databases.



                                                          Out of about 100 tables and 600 columns, I found a handful of inconsistencies, and one column that was defined as a floating point in one database and an integer in the other. That last one turned out to be a godsend, because it unearthed a problem that had been plaguing one of the databases for years.



                                                          The model for the metadatabase was suggested by the system tables in question. The queries were not hard to construct, revolving mostly around group by and having count(database name) = 1.



                                                          In your case, with 700 production databases, you might want to automate the first two steps more than I did with just two databases to compare. But the idea is similar.






                                                          share|improve this answer






























                                                            1














                                                            I am including this answer for the sake of a new question that was marked as a duplicate.



                                                            I once had to compare two production databases and find any schema differences between them. The only items of interest were tables that had been added or dropped and columns that had been added, removed, or altered. I no longer have the SQL scripts I developed, but what follows is the general strategy. And the database was not SQL Server, but I think the same strategy applies.



                                                            First, I created what can best be described as a metadatabase. The user tables of this database contained data descriptions copied from the system tables of the production databases. Things like Table Name, Column Name, Data Type and Precision. There was one more item, Database Name, that did not exist in either of the production databases.



                                                            Next, I developed scripts that coupled selects from the system tables of the production databases with inserts into the user tables of the metadatabase.



                                                            Finally, I developed queries to find tables that existed in one database but not the other, and columns from tables in both database that were only in one database, and columns with inconsistent definitions between the two databases.



                                                            Out of about 100 tables and 600 columns, I found a handful of inconsistencies, and one column that was defined as a floating point in one database and an integer in the other. That last one turned out to be a godsend, because it unearthed a problem that had been plaguing one of the databases for years.



                                                            The model for the metadatabase was suggested by the system tables in question. The queries were not hard to construct, revolving mostly around group by and having count(database name) = 1.



                                                            In your case, with 700 production databases, you might want to automate the first two steps more than I did with just two databases to compare. But the idea is similar.






                                                            share|improve this answer




























                                                              1












                                                              1








                                                              1







                                                              I am including this answer for the sake of a new question that was marked as a duplicate.



                                                              I once had to compare two production databases and find any schema differences between them. The only items of interest were tables that had been added or dropped and columns that had been added, removed, or altered. I no longer have the SQL scripts I developed, but what follows is the general strategy. And the database was not SQL Server, but I think the same strategy applies.



                                                              First, I created what can best be described as a metadatabase. The user tables of this database contained data descriptions copied from the system tables of the production databases. Things like Table Name, Column Name, Data Type and Precision. There was one more item, Database Name, that did not exist in either of the production databases.



                                                              Next, I developed scripts that coupled selects from the system tables of the production databases with inserts into the user tables of the metadatabase.



                                                              Finally, I developed queries to find tables that existed in one database but not the other, and columns from tables in both database that were only in one database, and columns with inconsistent definitions between the two databases.



                                                              Out of about 100 tables and 600 columns, I found a handful of inconsistencies, and one column that was defined as a floating point in one database and an integer in the other. That last one turned out to be a godsend, because it unearthed a problem that had been plaguing one of the databases for years.



                                                              The model for the metadatabase was suggested by the system tables in question. The queries were not hard to construct, revolving mostly around group by and having count(database name) = 1.



                                                              In your case, with 700 production databases, you might want to automate the first two steps more than I did with just two databases to compare. But the idea is similar.






                                                              share|improve this answer















                                                              I am including this answer for the sake of a new question that was marked as a duplicate.



                                                              I once had to compare two production databases and find any schema differences between them. The only items of interest were tables that had been added or dropped and columns that had been added, removed, or altered. I no longer have the SQL scripts I developed, but what follows is the general strategy. And the database was not SQL Server, but I think the same strategy applies.



                                                              First, I created what can best be described as a metadatabase. The user tables of this database contained data descriptions copied from the system tables of the production databases. Things like Table Name, Column Name, Data Type and Precision. There was one more item, Database Name, that did not exist in either of the production databases.



                                                              Next, I developed scripts that coupled selects from the system tables of the production databases with inserts into the user tables of the metadatabase.



                                                              Finally, I developed queries to find tables that existed in one database but not the other, and columns from tables in both database that were only in one database, and columns with inconsistent definitions between the two databases.



                                                              Out of about 100 tables and 600 columns, I found a handful of inconsistencies, and one column that was defined as a floating point in one database and an integer in the other. That last one turned out to be a godsend, because it unearthed a problem that had been plaguing one of the databases for years.



                                                              The model for the metadatabase was suggested by the system tables in question. The queries were not hard to construct, revolving mostly around group by and having count(database name) = 1.



                                                              In your case, with 700 production databases, you might want to automate the first two steps more than I did with just two databases to compare. But the idea is similar.







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Sep 6 '18 at 18:58

























                                                              answered Sep 6 '18 at 18:22









                                                              Walter MittyWalter Mitty

                                                              3,2941317




                                                              3,2941317























                                                                  1














                                                                  I had this exact same question and I believe that the Microsoft SQL Server Management Studio (SSMS) has a much easier/simpler solution than anything I saw here. I have a production site with MS SQL Server Express and soon to be several more where I don't want to have to install VisualStudio or other applications other than SSMS.



                                                                  So within SSMS, right click on the database to get the schema for. Select Tasks > Generate Scripts... to open a wizard to script the schema and configuration for the entire database (or selected objects if you want). I kept all the default options except the path/filename, but the tool has a plethora of options. The wizard created one SQL which I copied via OneDrive back to my PC. I then used Notepad++ to compare the SQL to a file generated in the same way against my SIT database. You have to filter out hits from the date/time in comments, but otherwise it is a great comparison of the two databases.



                                                                  Presto! Writing this up was significantly harder than doing the actual compare.






                                                                  share|improve this answer






























                                                                    1














                                                                    I had this exact same question and I believe that the Microsoft SQL Server Management Studio (SSMS) has a much easier/simpler solution than anything I saw here. I have a production site with MS SQL Server Express and soon to be several more where I don't want to have to install VisualStudio or other applications other than SSMS.



                                                                    So within SSMS, right click on the database to get the schema for. Select Tasks > Generate Scripts... to open a wizard to script the schema and configuration for the entire database (or selected objects if you want). I kept all the default options except the path/filename, but the tool has a plethora of options. The wizard created one SQL which I copied via OneDrive back to my PC. I then used Notepad++ to compare the SQL to a file generated in the same way against my SIT database. You have to filter out hits from the date/time in comments, but otherwise it is a great comparison of the two databases.



                                                                    Presto! Writing this up was significantly harder than doing the actual compare.






                                                                    share|improve this answer




























                                                                      1












                                                                      1








                                                                      1







                                                                      I had this exact same question and I believe that the Microsoft SQL Server Management Studio (SSMS) has a much easier/simpler solution than anything I saw here. I have a production site with MS SQL Server Express and soon to be several more where I don't want to have to install VisualStudio or other applications other than SSMS.



                                                                      So within SSMS, right click on the database to get the schema for. Select Tasks > Generate Scripts... to open a wizard to script the schema and configuration for the entire database (or selected objects if you want). I kept all the default options except the path/filename, but the tool has a plethora of options. The wizard created one SQL which I copied via OneDrive back to my PC. I then used Notepad++ to compare the SQL to a file generated in the same way against my SIT database. You have to filter out hits from the date/time in comments, but otherwise it is a great comparison of the two databases.



                                                                      Presto! Writing this up was significantly harder than doing the actual compare.






                                                                      share|improve this answer















                                                                      I had this exact same question and I believe that the Microsoft SQL Server Management Studio (SSMS) has a much easier/simpler solution than anything I saw here. I have a production site with MS SQL Server Express and soon to be several more where I don't want to have to install VisualStudio or other applications other than SSMS.



                                                                      So within SSMS, right click on the database to get the schema for. Select Tasks > Generate Scripts... to open a wizard to script the schema and configuration for the entire database (or selected objects if you want). I kept all the default options except the path/filename, but the tool has a plethora of options. The wizard created one SQL which I copied via OneDrive back to my PC. I then used Notepad++ to compare the SQL to a file generated in the same way against my SIT database. You have to filter out hits from the date/time in comments, but otherwise it is a great comparison of the two databases.



                                                                      Presto! Writing this up was significantly harder than doing the actual compare.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited 2 hours ago

























                                                                      answered Jan 8 at 17:02









                                                                      RBrownRBrown

                                                                      114




                                                                      114























                                                                          0














                                                                          A great tool I use (although not updated in a while still works) is AdeptSqlDiff



                                                                          Does both schema compares as well as data comparisons. Just like RedGate there is a cost but also a 30 day trial. And the price is pretty reasonable.






                                                                          share|improve this answer




























                                                                            0














                                                                            A great tool I use (although not updated in a while still works) is AdeptSqlDiff



                                                                            Does both schema compares as well as data comparisons. Just like RedGate there is a cost but also a 30 day trial. And the price is pretty reasonable.






                                                                            share|improve this answer


























                                                                              0












                                                                              0








                                                                              0







                                                                              A great tool I use (although not updated in a while still works) is AdeptSqlDiff



                                                                              Does both schema compares as well as data comparisons. Just like RedGate there is a cost but also a 30 day trial. And the price is pretty reasonable.






                                                                              share|improve this answer













                                                                              A great tool I use (although not updated in a while still works) is AdeptSqlDiff



                                                                              Does both schema compares as well as data comparisons. Just like RedGate there is a cost but also a 30 day trial. And the price is pretty reasonable.







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Oct 14 '15 at 19:25









                                                                              TombMediaTombMedia

                                                                              1012




                                                                              1012























                                                                                  0














                                                                                  Maybe this free script https://github.com/dlevsha/compalex can help you. It support Microsoft SQL Server.




                                                                                  Compalex is a free lightweight script to compare two database schemas. It
                                                                                  supports MySQL, MS SQL Server and PostgreSQL.




                                                                                  You can try demo here



                                                                                  http://demo.compalex.net/






                                                                                  share|improve this answer




























                                                                                    0














                                                                                    Maybe this free script https://github.com/dlevsha/compalex can help you. It support Microsoft SQL Server.




                                                                                    Compalex is a free lightweight script to compare two database schemas. It
                                                                                    supports MySQL, MS SQL Server and PostgreSQL.




                                                                                    You can try demo here



                                                                                    http://demo.compalex.net/






                                                                                    share|improve this answer


























                                                                                      0












                                                                                      0








                                                                                      0







                                                                                      Maybe this free script https://github.com/dlevsha/compalex can help you. It support Microsoft SQL Server.




                                                                                      Compalex is a free lightweight script to compare two database schemas. It
                                                                                      supports MySQL, MS SQL Server and PostgreSQL.




                                                                                      You can try demo here



                                                                                      http://demo.compalex.net/






                                                                                      share|improve this answer













                                                                                      Maybe this free script https://github.com/dlevsha/compalex can help you. It support Microsoft SQL Server.




                                                                                      Compalex is a free lightweight script to compare two database schemas. It
                                                                                      supports MySQL, MS SQL Server and PostgreSQL.




                                                                                      You can try demo here



                                                                                      http://demo.compalex.net/







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered Dec 23 '15 at 11:55









                                                                                      DLevshaDLevsha

                                                                                      1




                                                                                      1























                                                                                          0














                                                                                          There are many third party tools out there which will do schema and data compare, and synchronization. Two tools you can use are the ones my team and I have developed, xSQL Schema Compare for schema comparisons and xSQL Data Compare for data comparisons between objects with the same schema. Hope this helps!


                                                                                          Disclaimer: I'm affiliated to xSQL






                                                                                          share|improve this answer






























                                                                                            0














                                                                                            There are many third party tools out there which will do schema and data compare, and synchronization. Two tools you can use are the ones my team and I have developed, xSQL Schema Compare for schema comparisons and xSQL Data Compare for data comparisons between objects with the same schema. Hope this helps!


                                                                                            Disclaimer: I'm affiliated to xSQL






                                                                                            share|improve this answer




























                                                                                              0












                                                                                              0








                                                                                              0







                                                                                              There are many third party tools out there which will do schema and data compare, and synchronization. Two tools you can use are the ones my team and I have developed, xSQL Schema Compare for schema comparisons and xSQL Data Compare for data comparisons between objects with the same schema. Hope this helps!


                                                                                              Disclaimer: I'm affiliated to xSQL






                                                                                              share|improve this answer















                                                                                              There are many third party tools out there which will do schema and data compare, and synchronization. Two tools you can use are the ones my team and I have developed, xSQL Schema Compare for schema comparisons and xSQL Data Compare for data comparisons between objects with the same schema. Hope this helps!


                                                                                              Disclaimer: I'm affiliated to xSQL







                                                                                              share|improve this answer














                                                                                              share|improve this answer



                                                                                              share|improve this answer








                                                                                              edited Oct 10 '16 at 7:03

























                                                                                              answered Jul 13 '16 at 13:03









                                                                                              Endi ZhupaniEndi Zhupani

                                                                                              1315




                                                                                              1315























                                                                                                  0














                                                                                                  There is a lot of tools on the market which you might use to get the job done. My company is using ApexSQL Diff for both comparison and sync because it is free for Azure, but you can’t go wrong with either Devart or Redgate tools.






                                                                                                  share|improve this answer




























                                                                                                    0














                                                                                                    There is a lot of tools on the market which you might use to get the job done. My company is using ApexSQL Diff for both comparison and sync because it is free for Azure, but you can’t go wrong with either Devart or Redgate tools.






                                                                                                    share|improve this answer


























                                                                                                      0












                                                                                                      0








                                                                                                      0







                                                                                                      There is a lot of tools on the market which you might use to get the job done. My company is using ApexSQL Diff for both comparison and sync because it is free for Azure, but you can’t go wrong with either Devart or Redgate tools.






                                                                                                      share|improve this answer













                                                                                                      There is a lot of tools on the market which you might use to get the job done. My company is using ApexSQL Diff for both comparison and sync because it is free for Azure, but you can’t go wrong with either Devart or Redgate tools.







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered Apr 21 '17 at 15:53









                                                                                                      MspajaMspaja

                                                                                                      21124




                                                                                                      21124























                                                                                                          0














                                                                                                          I'm a fan of SQL DBDiff, which is an open source tool you can use to compare tables, views, functions, users, etc. of two instances of SQL Server databases and generate a change script between the source and destination databases.






                                                                                                          share|improve this answer




























                                                                                                            0














                                                                                                            I'm a fan of SQL DBDiff, which is an open source tool you can use to compare tables, views, functions, users, etc. of two instances of SQL Server databases and generate a change script between the source and destination databases.






                                                                                                            share|improve this answer


























                                                                                                              0












                                                                                                              0








                                                                                                              0







                                                                                                              I'm a fan of SQL DBDiff, which is an open source tool you can use to compare tables, views, functions, users, etc. of two instances of SQL Server databases and generate a change script between the source and destination databases.






                                                                                                              share|improve this answer













                                                                                                              I'm a fan of SQL DBDiff, which is an open source tool you can use to compare tables, views, functions, users, etc. of two instances of SQL Server databases and generate a change script between the source and destination databases.







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered May 29 '17 at 3:46









                                                                                                              ShridharShridhar

                                                                                                              1112




                                                                                                              1112























                                                                                                                  0














                                                                                                                  Check this out:



                                                                                                                  SELECT TABLE_SCHEMA ,
                                                                                                                  TABLE_NAME ,
                                                                                                                  COLUMN_NAME ,
                                                                                                                  ORDINAL_POSITION ,
                                                                                                                  COLUMN_DEFAULT ,
                                                                                                                  DATA_TYPE ,
                                                                                                                  CHARACTER_MAXIMUM_LENGTH ,
                                                                                                                  NUMERIC_PRECISION ,
                                                                                                                  NUMERIC_PRECISION_RADIX ,
                                                                                                                  NUMERIC_SCALE ,
                                                                                                                  DATETIME_PRECISION
                                                                                                                  FROM INFORMATION_SCHEMA.COLUMNS
                                                                                                                  where TABLE_SCHEMA in ('dbo','meta')
                                                                                                                  and table_name in (select name from sys.tables)
                                                                                                                  order by TABLE_SCHEMA , TABLE_NAME ,ORDINAL_POSITION


                                                                                                                  enter image description here






                                                                                                                  share|improve this answer



















                                                                                                                  • 3





                                                                                                                    This really needs to be about comparing, not just getting the schema

                                                                                                                    – Mark Sinkinson
                                                                                                                    Mar 7 '18 at 7:18











                                                                                                                  • I'll just leave it here encase it helps others. It helped me

                                                                                                                    – Jeremy Thompson
                                                                                                                    Mar 8 '18 at 10:49
















                                                                                                                  0














                                                                                                                  Check this out:



                                                                                                                  SELECT TABLE_SCHEMA ,
                                                                                                                  TABLE_NAME ,
                                                                                                                  COLUMN_NAME ,
                                                                                                                  ORDINAL_POSITION ,
                                                                                                                  COLUMN_DEFAULT ,
                                                                                                                  DATA_TYPE ,
                                                                                                                  CHARACTER_MAXIMUM_LENGTH ,
                                                                                                                  NUMERIC_PRECISION ,
                                                                                                                  NUMERIC_PRECISION_RADIX ,
                                                                                                                  NUMERIC_SCALE ,
                                                                                                                  DATETIME_PRECISION
                                                                                                                  FROM INFORMATION_SCHEMA.COLUMNS
                                                                                                                  where TABLE_SCHEMA in ('dbo','meta')
                                                                                                                  and table_name in (select name from sys.tables)
                                                                                                                  order by TABLE_SCHEMA , TABLE_NAME ,ORDINAL_POSITION


                                                                                                                  enter image description here






                                                                                                                  share|improve this answer



















                                                                                                                  • 3





                                                                                                                    This really needs to be about comparing, not just getting the schema

                                                                                                                    – Mark Sinkinson
                                                                                                                    Mar 7 '18 at 7:18











                                                                                                                  • I'll just leave it here encase it helps others. It helped me

                                                                                                                    – Jeremy Thompson
                                                                                                                    Mar 8 '18 at 10:49














                                                                                                                  0












                                                                                                                  0








                                                                                                                  0







                                                                                                                  Check this out:



                                                                                                                  SELECT TABLE_SCHEMA ,
                                                                                                                  TABLE_NAME ,
                                                                                                                  COLUMN_NAME ,
                                                                                                                  ORDINAL_POSITION ,
                                                                                                                  COLUMN_DEFAULT ,
                                                                                                                  DATA_TYPE ,
                                                                                                                  CHARACTER_MAXIMUM_LENGTH ,
                                                                                                                  NUMERIC_PRECISION ,
                                                                                                                  NUMERIC_PRECISION_RADIX ,
                                                                                                                  NUMERIC_SCALE ,
                                                                                                                  DATETIME_PRECISION
                                                                                                                  FROM INFORMATION_SCHEMA.COLUMNS
                                                                                                                  where TABLE_SCHEMA in ('dbo','meta')
                                                                                                                  and table_name in (select name from sys.tables)
                                                                                                                  order by TABLE_SCHEMA , TABLE_NAME ,ORDINAL_POSITION


                                                                                                                  enter image description here






                                                                                                                  share|improve this answer













                                                                                                                  Check this out:



                                                                                                                  SELECT TABLE_SCHEMA ,
                                                                                                                  TABLE_NAME ,
                                                                                                                  COLUMN_NAME ,
                                                                                                                  ORDINAL_POSITION ,
                                                                                                                  COLUMN_DEFAULT ,
                                                                                                                  DATA_TYPE ,
                                                                                                                  CHARACTER_MAXIMUM_LENGTH ,
                                                                                                                  NUMERIC_PRECISION ,
                                                                                                                  NUMERIC_PRECISION_RADIX ,
                                                                                                                  NUMERIC_SCALE ,
                                                                                                                  DATETIME_PRECISION
                                                                                                                  FROM INFORMATION_SCHEMA.COLUMNS
                                                                                                                  where TABLE_SCHEMA in ('dbo','meta')
                                                                                                                  and table_name in (select name from sys.tables)
                                                                                                                  order by TABLE_SCHEMA , TABLE_NAME ,ORDINAL_POSITION


                                                                                                                  enter image description here







                                                                                                                  share|improve this answer












                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer










                                                                                                                  answered Mar 7 '18 at 3:20









                                                                                                                  Jeremy ThompsonJeremy Thompson

                                                                                                                  1268




                                                                                                                  1268








                                                                                                                  • 3





                                                                                                                    This really needs to be about comparing, not just getting the schema

                                                                                                                    – Mark Sinkinson
                                                                                                                    Mar 7 '18 at 7:18











                                                                                                                  • I'll just leave it here encase it helps others. It helped me

                                                                                                                    – Jeremy Thompson
                                                                                                                    Mar 8 '18 at 10:49














                                                                                                                  • 3





                                                                                                                    This really needs to be about comparing, not just getting the schema

                                                                                                                    – Mark Sinkinson
                                                                                                                    Mar 7 '18 at 7:18











                                                                                                                  • I'll just leave it here encase it helps others. It helped me

                                                                                                                    – Jeremy Thompson
                                                                                                                    Mar 8 '18 at 10:49








                                                                                                                  3




                                                                                                                  3





                                                                                                                  This really needs to be about comparing, not just getting the schema

                                                                                                                  – Mark Sinkinson
                                                                                                                  Mar 7 '18 at 7:18





                                                                                                                  This really needs to be about comparing, not just getting the schema

                                                                                                                  – Mark Sinkinson
                                                                                                                  Mar 7 '18 at 7:18













                                                                                                                  I'll just leave it here encase it helps others. It helped me

                                                                                                                  – Jeremy Thompson
                                                                                                                  Mar 8 '18 at 10:49





                                                                                                                  I'll just leave it here encase it helps others. It helped me

                                                                                                                  – Jeremy Thompson
                                                                                                                  Mar 8 '18 at 10:49











                                                                                                                  0














                                                                                                                  I use this free (and open source) tool: OpenDBDiff






                                                                                                                  share|improve this answer




























                                                                                                                    0














                                                                                                                    I use this free (and open source) tool: OpenDBDiff






                                                                                                                    share|improve this answer


























                                                                                                                      0












                                                                                                                      0








                                                                                                                      0







                                                                                                                      I use this free (and open source) tool: OpenDBDiff






                                                                                                                      share|improve this answer













                                                                                                                      I use this free (and open source) tool: OpenDBDiff







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered Dec 21 '18 at 10:47









                                                                                                                      TommyTommy

                                                                                                                      1011




                                                                                                                      1011






























                                                                                                                          draft saved

                                                                                                                          draft discarded




















































                                                                                                                          Thanks for contributing an answer to Database Administrators Stack Exchange!


                                                                                                                          • Please be sure to answer the question. Provide details and share your research!

                                                                                                                          But avoid



                                                                                                                          • Asking for help, clarification, or responding to other answers.

                                                                                                                          • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                          To learn more, see our tips on writing great answers.




                                                                                                                          draft saved


                                                                                                                          draft discarded














                                                                                                                          StackExchange.ready(
                                                                                                                          function () {
                                                                                                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f95236%2fhow-can-i-compare-the-schema-of-two-databases%23new-answer', 'question_page');
                                                                                                                          }
                                                                                                                          );

                                                                                                                          Post as a guest















                                                                                                                          Required, but never shown





















































                                                                                                                          Required, but never shown














                                                                                                                          Required, but never shown












                                                                                                                          Required, but never shown







                                                                                                                          Required, but never shown

































                                                                                                                          Required, but never shown














                                                                                                                          Required, but never shown












                                                                                                                          Required, but never shown







                                                                                                                          Required, but never shown







                                                                                                                          Popular posts from this blog

                                                                                                                          Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

                                                                                                                          Always On Availability groups resolving state after failover - Remote harden of transaction...

                                                                                                                          update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...