Method AddColumn
- Namespace
- YndigoBlue.Velocity.Model
- Assembly
- YndigoBlue.Velocity.dll
AddColumn(string, DataType, bool, bool, int, byte, byte)
Adds a new column to an already-deployed table as a schema migration operation.
public Column AddColumn(string name, DataType dataType, bool notNull = false, bool autoGenerate = false, int size = 0, byte precision = 0, byte scale = 0)
Parameters
namestringThe name of the column.
dataTypeDataTypeThe data type of the column.
notNullboolWhether the column should have a NOT NULL constraint. Defaults to
false.autoGenerateboolWhether the column value should be auto-generated (identity/sequence). Defaults to
false.sizeintThe size of the column for variable-length types such as
VarChar. Defaults to0(no size limit).precisionbyteThe total number of significant digits for numeric types. Defaults to
0.scalebyteThe number of digits to the right of the decimal point for numeric types. Defaults to
0.
Returns
- Column
The newly created Column with SchemaUpdate set to
true.
Remarks
This method is for schema migration — adding a column to a table that already exists in the database.
It automatically sets SchemaUpdate to true, which causes
UpdateSchema(Schema, bool) to issue an
ALTER TABLE ADD COLUMN statement for this column.
For defining columns as part of an initial schema deployment, use CreateColumn(string, DataType, bool, bool, int, byte, byte) instead.
AddColumn(string, DataType, DefaultConstraintType, IDefaultItem, bool, bool, int, byte, byte)
Adds a new column to an already-deployed table as a schema migration operation, with a default value applied to existing rows.
public Column AddColumn(string name, DataType dataType, DefaultConstraintType existingRowType, IDefaultItem existingRowValue, bool notNull = false, bool autoGenerate = false, int size = 0, byte precision = 0, byte scale = 0)
Parameters
namestringThe name of the column.
dataTypeDataTypeThe data type of the column.
existingRowTypeDefaultConstraintTypeThe type of default value to apply to existing rows.
existingRowValueIDefaultItemThe default value item to apply to existing rows.
notNullboolWhether the column should have a NOT NULL constraint. Defaults to
false.autoGenerateboolWhether the column value should be auto-generated (identity/sequence). Defaults to
false.sizeintThe size of the column for variable-length types such as
VarChar. Defaults to0(no size limit).precisionbyteThe total number of significant digits for numeric types. Defaults to
0.scalebyteThe number of digits to the right of the decimal point for numeric types. Defaults to
0.
Returns
- Column
The newly created Column with SchemaUpdate set to
true.
Remarks
This overload is for schema migration where existing rows in the table need to be backfilled
with a default value when the column is added. The existingRowValue is applied
to all rows that exist at the time the column is created.
It automatically sets SchemaUpdate to true, which causes
UpdateSchema(Schema, bool) to issue an
ALTER TABLE ADD COLUMN statement with a backfill default for this column.
For defining columns as part of an initial schema deployment, use CreateColumn(string, DataType, bool, bool, int, byte, byte) instead.