SQL Server 2008 Compare two different database tables for column name, data type and length
Resolved it my self :
SELECT
T.[name] AS [table_name], AC.[name] AS [column_name],
TY.[name] AS system_data_type
FROM [master].sys.[tables] AS T
INNER JOIN [master].sys.[all_columns] AC ON T.[object_id] = AC.[object_id]
INNER JOIN [master].sys.[types] TY ON AC.[system_type_id] = TY.[system_type_id]
EXCEPT
SELECT
T.[name] AS [table_name], AC.[name] AS [column_name],
TY.[name] AS system_data_type
FROM test.sys.[tables] AS T
INNER JOIN test.sys.[all_columns] AC ON T.[object_id] = AC.[object_id]
INNER JOIN test.sys.[types] TY ON AC.[system_type_id] = TY.[system_type_id]
This will give you the list of Columns along with Table Name, Column Name and Data Type that is in master but not exists or different from test.
How do I compare two tables in different databases
Yes, this can be done.
You could use something like a three part identifier to identify the tables in different database. Kinda like this :
RICSTOREV341.dbo.Price_Tab
Then you can perform a join on the primary key and fetch the result.
two different databases (data were copied from one 2 another) and compare their data
SELECT * FROM old.A WHERE old.A.name NOT IN (SELECT Name FROM new.B)
This will bring up all records from the original table which haven't been copied over to the new table. Bear in mind that this is MySQL syntax, so you may need to adapt it for SQL Server 2008.
Obviously this assumes that name
is a unique column. If it isn't, you may need to post more specific detail on your particular problem.
Compare Two Tables In two Databases with the same Table Structure
I think you want not exists
:
update a2
set min_qty = 0, max_qty = 0, unit_cost = 0
from database2.asset_table a2
where not exists (
select 1 from database1.asset_table a1 where a1.asset_id = a2.asset_id
)
Comparing values of 2 tables and listing the rows that are different
This will give you everything in A that's not in B
select * from tableA
Except
select * from tableB
and vice-versa
select * from tableB
Except
select * from tableA
Edit: Joined this way:
(select * from tableA
Except
select * from tableB)
union all
(select * from tableB
Except
select * from tableA)
Related Topics
Is Varchar(Max) Always Preferable
How to Swap Column Values in SQL Server 2008
Select Distinct on One Column, Return Multiple Other Columns (SQL Server)
Using Pivot Table with Column and Row Totals in SQL Server 2008
Concatenate Many Rows into a Single Text String with Grouping
Pros and Cons of Autoincrement Keys on "Every Table"
How to Store Longitude & Latitude as a Geography in SQL Server 2014
Microsoft SQL Server Management Studio - Query Result as Text
SQL - Stored Procedure with Select Statement Using in (@Variable_Commadelimitedlistofids)
Is There a Coalesce-Like Function in Excel
How to Export Data with Oracle SQL Developer
"Like" Operator in Inner Join in SQL
Calculate Row Wise Sum - SQL Server
How to Tell If I Have Uncommitted Work in an Oracle Transaction
Inventory Average Cost Calculation in SQL
SQL Update Records with Row_Number()
Counting Number of Records Hour by Hour Between Two Dates in Oracle