本文整理汇总了C#中Column.AddDefaultConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# Column.AddDefaultConstraint方法的具体用法?C# Column.AddDefaultConstraint怎么用?C# Column.AddDefaultConstraint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Column
的用法示例。
在下文中一共展示了Column.AddDefaultConstraint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateStgTable
public void CreateStgTable()
{
// Create the new table in the appropriate filegroup for the SWITCH
foreach (Column c in partitionTable.Columns)
{
// Populate the table with each column and associated properties from the partition table
Column stgCol = new Column(stgTable, c.Name, c.DataType);
stgCol.Collation = c.Collation;
stgCol.Nullable = c.Nullable;
stgCol.Computed = c.Computed;
stgCol.ComputedText = c.ComputedText;
stgCol.Default = c.Default;
// Apply default constraint value, if present, as a default value
if (c.DefaultConstraint != null)
{
stgCol.AddDefaultConstraint(stgTable.Name + "_" + c.DefaultConstraint.Name);
stgCol.DefaultConstraint.Text = c.DefaultConstraint.Text;
}
stgCol.IsPersisted = c.IsPersisted;
stgCol.DefaultSchema = c.DefaultSchema;
stgCol.RowGuidCol = c.RowGuidCol;
if (srv.VersionMajor >= 10)
{
stgCol.IsFileStream = c.IsFileStream;
stgCol.IsSparse = c.IsSparse;
stgCol.IsColumnSet = c.IsColumnSet;
}
stgTable.Columns.Add(stgCol);
}
// Match other new table attributes to the partition table; required for SWITCH compatibility
stgTable.AnsiNullsStatus = partitionTable.AnsiNullsStatus;
stgTable.QuotedIdentifierStatus = partitionTable.QuotedIdentifierStatus;
// Calculate the filegroup associated with the partition nunber to switch; create temp table in that filegroup
stgTable.FileGroup = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];
stgTable.TextFileGroup = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];
if (srv.VersionMajor >= 10)
{
// Define compression property to match by creating a Physical Partition object
PhysicalPartition stgPartition = new PhysicalPartition(stgTable, 1, partitionTable.PhysicalPartitions[partitionNumber - 1].DataCompression);
stgTable.PhysicalPartitions.Add(stgPartition);
}
scriptChunks.Add(stgTable.Script());
if (executeCommands) stgTable.Create();
}
示例2: AddTableButton_Click
private void AddTableButton_Click(object sender, System.EventArgs e)
{
Database db;
Table tbl;
Column col;
Index idx;
Default dflt;
Cursor csr = null;
try
{
csr = this.Cursor; // Save the old cursor
this.Cursor = Cursors.WaitCursor; // Display the waiting cursor
// Show the current tables for the selected database
db = (Database)DatabasesComboBox.SelectedItem;
if (db.Tables.Contains(TableNameTextBox.Text) == false)
{
// Create an empty string default
dflt = db.Defaults["dfltEmptyString"];
if (dflt == null)
{
dflt = new Default(db, "dfltEmptyString");
dflt.TextHeader = "CREATE DEFAULT [dbo].[dfltEmptyString] AS ";
dflt.TextBody = @"'';";
dflt.Create();
}
// Create a new table object
tbl = new Table(db,
TableNameTextBox.Text, db.DefaultSchema);
// Add the first column
col = new Column(tbl, @"Column1", DataType.Int);
tbl.Columns.Add(col);
col.Nullable = false;
col.Identity = true;
col.IdentitySeed = 1;
col.IdentityIncrement = 1;
// Add the primary key index
idx = new Index(tbl, @"PK_" + TableNameTextBox.Text);
tbl.Indexes.Add(idx);
idx.IndexedColumns.Add(new IndexedColumn(idx, col.Name));
idx.IsClustered = true;
idx.IsUnique = true;
idx.IndexKeyType = IndexKeyType.DriPrimaryKey;
// Add the second column
col = new Column(tbl, @"Column2", DataType.NVarChar(1024));
tbl.Columns.Add(col);
col.DataType.MaximumLength = 1024;
col.AddDefaultConstraint(null); // Use SQL Server default naming
col.DefaultConstraint.Text = Properties.Resources.DefaultConstraintText;
col.Nullable = false;
// Add the third column
col = new Column(tbl, @"Column3", DataType.DateTime);
tbl.Columns.Add(col);
col.Nullable = false;
// Create the table
tbl.Create();
// Refresh list and select the one we just created
ShowTables();
// Clear selected items
TablesComboBox.SelectedIndex = -1;
// Find the table just created
TablesComboBox.SelectedIndex = TablesComboBox.FindStringExact(tbl.ToString());
}
else
{
ExceptionMessageBox emb = new ExceptionMessageBox();
emb.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.TableExists, TableNameTextBox.Text);
emb.Show(this);
}
}
catch (SmoException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
}
finally
{
this.Cursor = csr; // Restore the original cursor
}
}
示例3: CreateColumn
/// <summary>
/// Creates column in the table
/// </summary>
/// <param name="aTable">Table, <see cref="Table"/></param>
/// <param name="column">Column description <see cref="DataColumnDbo"/></param>
/// <returns>SMO column, <see cref="Column"/></returns>
private static Column CreateColumn(Table aTable, DataColumnDbo column)
{
SqlDataType sqlType = (SqlDataType)Enum.Parse(typeof(SqlDataType), column.SqlDataType, true);
int length;
if (column.MaximumLength.HasValue && column.MaximumLength.Value > 0)
length = column.MaximumLength.Value;
else
length = column.NumericPrecision ?? 0;
var newColumn = new Column(aTable, column.Name,
GetSmoType(sqlType, length, column.NumericPrecision ?? 0, column.NumericScale ?? 0))
{
Identity = column.IsIdentity,
Nullable = column.IsNullable,
};
if (!String.IsNullOrEmpty(column.Default))
{
newColumn.AddDefaultConstraint();
newColumn.DefaultConstraint.Text = column.Default;
}
if (newColumn.Identity)
{
newColumn.IdentityIncrement = 1;
newColumn.IdentitySeed = 1;
}
aTable.Columns.Add(newColumn);
return newColumn;
}