I am working on a project of Data Centralization. I have to transfer data from two databases into a third newly created master database.The existing databases hold the same type of data, the tables are the same etc. But before that, I need to check whether the master tables from the existing two databases are the same i.e. the column names, number etc are same of the two same tables in both the databases. For e.g. Both the databases have a table called SROMaster. I need to check if SROMaster from db1 will hold the same columns as SROMaster from db2. Can someone help me? Thanks!
Not sure what platform/language you're using - but in any case, to test if a given table exists, you can use this T-SQL to do the job:
SELECT t.*
FROM sys.tables t
WHERE t.Name = 'SROMaster'
That will return a row with all the info about the table - if it exists - otherwise you can nothing back.
Once you have the table, you can check what columns the table has by using:
SELECT c.*
FROM sys.columns c
INNER JOIN sys.tables t ON c.object_id = t.object_id
WHERE t.Name = 'SROMaster'
ORDER BY c.column_id
You'll get back a data set of rows with information about the columns - compare those two lists you're getting to see if you have the same columns in both table's SROMaster
table.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments