How to locate relevant tables or columns in a SQL Server database

73 Views Asked by At

I have imported 1000 sample rows from various tables into a SQL Server (let's call it SQLServer1).

I have also imported the rows into the second SQL Server (SQLServer2).

When I execute the following query on SQLServer2, I get no results, however when I execute the same query on SQLServer1, I get the expected results.

This is because I haven't imported all the rows from SQLServer1 to SQLServer2.

The problem is that I can't import all the data from SQLServer1 to SQLServer2 because some tables contain over 3 million rows.

Therefore, can someone let me know if there is a way to find out exactly data is required from the tables in SQLServer1 to get a result from SQLServer2?

Basically, I need to import only those rows into SQLServer2, that will produce the same result in SQLServer1.

I believe I would need to do apply some kind of DISTINCT clause or a LEFT / RIGHT JOIN to determine the rows/columns/data that is present in SQLServer1 that is not present in SQLServer2, but I'm not sure.

The tables look like the following:

enter image description here

Sample code is as follows:

CREATE TABLE #tmpTable 
(
    MakeName nvarchar(100),
    ModelName nvarchar(150),
    Cost money
)

INSERT #tmpTable 
VALUES (N'Ferrari', N'Testarossa', 52000.00),
       (N'Ferrari', N'355', 176000.00),
       (N'Porsche', N'911', 15600.00),
       (N'Porsche', N'924', 9200.00),
       (N'Porsche', N'944', 15960.00),
       (N'Ferrari', N'Testarossa', 176000.00),
       (N'Aston Martin', N'DB4', 23600.00),
       (N'Aston Martin', N'DB5', 39600.00)

Any thoughts?

The code is as follows:

SELECT Make.MakeName, Model.ModelName, Stock.Cost 
FROM Data.Stock
INNER JOIN Data.Model ON Model.ModelID = Stock.ModelID
INNER JOIN Data.Make ON Make.MakeID = Model.MakeID
0

There are 0 best solutions below