using System; using System.Data; class Program { static void Main(string[] args) { DataTable dt = new DataTable("Table-1"); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Field1", typeof(string)).MaxLength = 50; UniqueConstraint uc1 = new UniqueConstraint("UniqueConstraint", dt.Columns["Field1"]); dt.Constraints.Add(uc1); OutputConstraintProperties(dt); } private static void OutputConstraintProperties(DataTable dt) { Console.WriteLine(dt.TableName); Console.WriteLine(dt.Constraints[0].ConstraintName); Console.WriteLine(((UniqueConstraint)dt.Constraints[0]).IsPrimaryKey); foreach (DataColumn col in ((UniqueConstraint)dt.Constraints[0]).Columns) { Console.WriteLine(col.ColumnName); } } }