You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Data/Schema/Sql/UniqueConstraintAdd.cs

43 lines
952 B

using System.Text;
namespace Connected.Data.Schema.Sql
{
internal class UniqueConstraintAdd : TableTransaction
{
public UniqueConstraintAdd(IndexDescriptor index)
{
Index = index;
}
private IndexDescriptor Index { get; }
protected override async Task OnExecute()
{
await Context.Execute(CommandText);
}
private string CommandText
{
get
{
var text = new StringBuilder();
text.AppendLine($"ALTER TABLE {Escape(Context.Schema.SchemaName(), Context.Schema.Name)}");
text.AppendLine($"ADD CONSTRAINT [{Context.GenerateConstraintName(Context.Schema.SchemaName(), Context.Schema.Name, ConstraintNameType.Index)}] UNIQUE NONCLUSTERED (");
var comma = string.Empty;
foreach (var column in Index.Columns)
{
text.AppendLine($"{comma}{Escape(column)} ASC");
comma = ",";
}
text.AppendLine($") ON {Escape(SchemaExtensions.FileGroup)}");
return text.ToString();
}
}
}
}