Welcome to MSDN Blogs Sign in | Join | Help

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);
c1.AddDefaultConstraint(
/*name optional*/);
c1.DefaultConstraint.Text =
"getdate()";
tbl.Columns.Add(c1);
tbl.Create();

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.

Published Tuesday, October 18, 2005 2:26 PM by mwories
Filed under: ,

Comments

# re: SMO Sample: Table column default constraint

Monday, January 07, 2008 1:30 AM by yang tang

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

can u provide a sample?

Anonymous comments are disabled
 
Page view tracker