2022-12-02 15:03:34 +01:00

32 lines
762 B
C#

using System.Text;
namespace Connected.Data.Schema.Sql
{
internal class PrimaryKeyAdd : ColumnTransaction
{
public PrimaryKeyAdd(ISchemaColumn column) : base(column)
{
}
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.PrimaryKey)}");
text.AppendLine($"PRIMARY KEY CLUSTERED ({Escape(Column.Name)}) ON {Escape(SchemaExtensions.FileGroup)}");
return text.ToString();
}
}
}
}