SMO Sample: Table column default constraint

Purpose of sample: show how a column constraint can be created.

Table tbl = new Table (db, "MyTestTable");
Column c1 = new Column(tbl, "c1", DataType.DateTime);
/*name optional*/);
c1.DefaultConstraint.Text =

Disclaimer: this sample doesn't handle exceptions and may not function as expected. Use at own risk. It is good practice to test an application before using it in production.

Comments (1)
  1. yang tang says:

    what if you add a column with default, not allow null in an existing table?

    can u provide a sample?

Comments are closed.

Skip to main content