/// <summary>
/// Translates this table into a SQL script
/// </summary>
/// <returns></returns>
public string Script()
{
var text = new StringBuilder();
text.AppendFormat("CREATE TABLE [{0}](\r\n", Name);
text.Append(Columns.Script());
if (Constraints.Count > 0)
{
text.AppendLine();
}
//add primary keys
foreach (var c in Constraints.Where(c => c.Type == ConstraintType.PrimaryKey))
{
text.AppendLine(" ," + c.Script());
}
text.AppendLine(");");
text.AppendLine();
//add indexes and constraints
foreach (var c in Constraints.Where(c => c.Type != ConstraintType.PrimaryKey))
{
text.AppendLine(c.Script());
}
return(text.ToString());
}