This article is half-done without your Comment! *** Please share your thoughts via Comment ***
SQL Server 2012 introduced a sp_describe_first_result_set stored procedure which you can use to compare the table definition.
When we are working with multiple schemas/servers, there are chances of a mistake like the same table having different data types in between the schemas/servers.
In that case, you can check your table definition manual, or you can use other system master tables for comparing the objects.
But using sp_describe_first_result_set, you can easily compare the object than any other option.
Please check below demonstration:
Create a sample SCHEMA:
1 2 |
CREATE SCHEMA test GO |
Create two sample tables:
Create these sample tables in the different schema with different data types.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
CREATE TABLE dbo.ABC ( ID INT PRIMARY KEY ,Name VARCHAR(MAX) ,Class CHAR(2) ) GO CREATE TABLE test.ABC ( ID BIGINT PRIMARY KEY ,Name NVARCHAR(MAX) ,Class CHAR(2) ) GO |
Execute below sp_describe_first_result_set, and compare the table definition:
1 2 |
EXEC sp_describe_first_result_set @tsql = N'select *from dbo.ABC' EXEC sp_describe_first_result_set @tsql = N'select *from test.ABC' |
Result:
Leave a Reply