I have a way to compare the column data which is stored in the cms_class table as xml. It works very well assuming the column names in both areas are the same. Below is the code for that.
Regarding creating a new field via the API. I believe you can look at the FieldEditor.ascx control for this. On about line 1980 of \CMSModules\AdminControls\Controls\Class\FieldEditor\FieldEditor.accx.cs you will find the SaveSelectedField() method that has all the "stuff" you need to create a new column in a table.
public static bool CreateCustomTableItem(DataClassInfo Dci, DataRow Row)
{
bool okInsert = false;
// Creates new Custom table item provider
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(ui);
if (Dci == null)
{
throw new Exception("Data class info cannot be null.");
}
else
{
// Creates new custom table item object
CustomTableItem newCustomTableItem = CustomTableItem.New(Dci.ClassName, customTableProvider);
List<string> classProperties = new List<string>();
// get the class definition
var doc = XDocument.Parse(Dci.ClassFormDefinition);
// get a list of all the tables properties by column value
List<string> elements = doc.Descendants("field").Select(el => el.Attribute("column").Value).ToList();
// got the class properties now compare
foreach (string s in elements)
{
// see if the class info contains the column in the data row passed in this method
if (Row.Table.Columns.Contains(s))
{
// contains the column so set a value
newCustomTableItem.SetValue(s, Row[s]);
okInsert = true;
}
}
if (okInsert)
{
// Inserts the custom table item into database
newCustomTableItem.Insert();
}
}
return okInsert;
}