public static string CreateColumn(IColumn c, DiffDefaultConstraint tempDefault = null) { string fullType = GetColumnType(c); var generatedAlways = c is SystemVersionedInfo.Column svc ? $"GENERATED ALWAYS AS ROW {(svc.SystemVersionColumnType == SystemVersionedInfo.ColumnType.Start ? "START" : "END")} HIDDEN" : null; var defaultConstraint = tempDefault != null ? $"CONSTRAINT {tempDefault.Name} DEFAULT " + Quote(c.SqlDbType, tempDefault.Definition) : c.Default != null ? $"CONSTRAINT DF_{c.Name} DEFAULT " + Quote(c.SqlDbType, c.Default) : null; return($" ".CombineIfNotEmpty( c.Name.SqlEscape(), fullType, c.Identity ? "IDENTITY " : null, generatedAlways, c.Collation != null ? ("COLLATE " + c.Collation) : null, c.Nullable ? "NULL" : "NOT NULL", defaultConstraint )); }
public static SqlPreCommand AlterTableAddColumn(ITable table, IColumn column, DiffDefaultConstraint tempDefault = null) { return(new SqlPreCommandSimple("ALTER TABLE {0} ADD {1}".FormatWith(table.Name, CreateColumn(column, tempDefault)))); }