Compare 2 Database all rows - different rows = output - sql

i need a little bit help.
I have a developer DB (dev_home), in this db are many tables.
I need a compare to another DB (real_home).
The Tables are the same, but the table_names not!
For example i develop # dev_home, in the table personal.
In this table i've created new field, which are not exist in #real_home DB.

There are tools that do this i.e. compare two different instances of a database or two different databases etc ..
Such as
Red-Gate's SQL data comparison tool
or
You can also use Microsoft Visual Studio 2015 Community Edition (Free)

Related

Comparing similar tables in different SQL Server databases

While Googling for a way to compare two tables (same schema) that are located in two different databases, I came across the tablediff.exe utility which works great for creating a script to make changes in table B so that it matches table A.
However, in my case I need changes to be made to table B only if the data in B is older than that of A. Otherwise, the change needs to be applied to table A.
Is there a way to do it using tablediff.exe, and if not is there any free command line alternative?
The Community (free) version of Visual Studio has 'Data Comparison...' for SQL projects. Right click on the object in SQL Server Object Explorer and specify Source and Target...
Here are some screen shots
Right click (in VS (Dark Mode) SQL Server project) in the SQL Server Object Explorer on the Table to compare.
Connect to the 2 instances
Then select the object(s) and voila!
I cannot comment on the conversation from above, but to add to SteveC comments, Visual Studio does have a Data Compare utility.
Tools > SQL Server > New Data Comparison

I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016

I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016!
Use System Information Schema Views. This should get you started:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
Use this query to get information of column structure in a database and compare against another db
use DB
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='YourTableName'
This is external software, but unless you have Visual Studio premium where the functionality is built in, you can use something like Red Gate Schema Compare as a trial version to compare and generate a script to synchronise your tables, stored procedures etc.

Compare two tables with different schema in SQL Server

I have two tables in different databases with different schema, how can I compare them both?
Let's say I have the DB1 with the table history.Table1 and another DB2 with the same table but in a different schema, backup.Table1.
Now I need to compare what's different besides the schema name obviously.
Try SQL Compare from Redgate. They allow you to compare pretty much everything from the actual data to the schema.
I dont believe there is any native functionality in sqlserver.
Compare SQL Server schemas and deploy differences fast
Compare and deploy SQL Server database contents

merging two databases

I have two distinct mssql databases with identical schemas but different data on one system. I want to merge the data between the two databases by adding the data from one into the other.
I tried to use Redgate Data Compare but couldn't find any instructions how to do it.
Are there any tools (or databases that have built-in tools) or instructions to make this job fairly simple?
xSQL Software has developed a set of tools for this type of database operations. You can use xSQL Data Compare. To achieve the result you require you specify the left and right database, do the compare and then, to add the data that are missing from the left db to the right db you need to uncheck sync for the right rows and generate and execute the script.
Here you can see the rows unchecked:
And as you can see, the script does not generate any DELETE statements, only INSERTS for the rows that are missing on the right DB
Hope this helps!
Disclosure: I'm affiliated to xSQL Software

How do you transfer all tables between databases using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data?
If this is not possible, could you advise on how I could do the following:
I have two databases, with the same table names, but one has more data than the other
They both have different database names (Table names are identical)
They are both on different servers
I need to get all of the additional data from the larger database, into the smaller database.
Both are MS SQL databases
Being that both are MS SQL Servers, on different hosts... why bother with CSV when you can setup a Linked Server instance so you can access one instance from the other via a SQL statement?
Make sure you have a valid user on the instance you want to retrieve data from - it must have access to the table(s)
Create the Linked Server instance
Reference the name in queries using four name syntax:
INSERT INTO db1.dbo.SmallerTable
SELECT *
FROM linked_server.db.dbo.LargerTable lt
WHERE NOT EXISTS(SELECT NULL
FROM db1.dbo.SmallerTable st
WHERE st.col = lt.col)
Replace WHERE st.col = lt.col with whatever criteria you consider to be duplicate values between the two tables.
There is also a very good tool by Redgate software that syncs data between two databases.
I've also used SQL scripter before to generate a SQL file with insert statements that you can run on the other database to insert the data.
If you right-click on the database, under the Tasks menu, you can use the Generate Scripts option to produce SQL scripts for all the tables and data. See this blog post for details. If you want to sync the second database with the first, then you're better off using something like Redgate as suggested in mpenrow's answer.