As part of a schema comparison program my company has, we needed to be able to identify check constraints that reference a specified column.
This method takes a SMO Table object, and the name of a column in that table.
// Assumes that column names within constraint text are bracketed.
public static List GetCheckConstraintsForColumn(
Table table,
string columnName
)
{
if (!columnName.StartsWith(“[“))
{
columnName = “[” + columnName + “]”;
}
List checkConstraintList = new List();
foreach (Check checkConstraint in table.Checks)
{
if (checkConstraint.Text.Contains(columnName))
{
checkConstraintList.Add(checkConstraint);
}
}
return checkConstraintList;
}
Hi thaanks for sharing this