Avatar of Sandiya
 asked on

Urgent: Get the missing column name


I've a table namesly "course" in database1 "db1" & another table "course" in database2 "db2". I want to compare two tables & check whether two table columns are equal. If not equal, I have to find out the extra column or missing column and datatype and add the extra/missing column at runtime using alter table command.

How to get data type & column name...
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Are the fields unique in there respective columns?

Try this:


Sounds like you need a full outer join, in a function that returns a table wherethe full outer join finds nulls.  Maybe one for each table.  Then that could be the input for a transaction, or another stored procedure to uptadte the tables as needed.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Kamal Khaleefa


i recommend the following

dim dt1 as new datattable=get data from course in db1
dim dt2 as new datattable=get data from course in db2

then write a for loop to compare the columns name
ex: for i as integer=0 to dt1. Columns.Count -1 ...
and then u can know what is the missing
and base on that create a sql statement to do the necessary modification and execute it

The problem is that i cannot do a sql query because only the target datatable is from sql and the source datatable is from salesforce.Iam doing an import of data from salesforce and export it to sqlserver.

I have done coding to import the data from salesforce and export it to sqlserver.But say if they have added a custom field in the salesforce  and so i have to a comparison between datatables and find the missing column and then add that column to the sql server table.

i need a logic to compare two datatables for column names and then check whether there are any columns missing and then add that column to the target table in sql server.
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks Codecruiser the code worked like a charm.I am able to identify the missing column and will proceed to do the coding for alter table.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.