Home All Groups Group Topic Archive Search About

SMO Table Scripts -- Defaults and Binding Rules

Author
30 Apr 2006 10:41 PM
Scott
I'm using SMO to script out some tables, but I can't figure out how to include
the column default field values or how to bind the user defined rules to
the columns. I'm using the options shown below:

---------------------------------
_createOptions.ClusteredIndexes = true;
_createOptions.Default = true;
_createOptions.Indexes = true;
_createOptions.NonClusteredIndexes = true;
_createOptions.Permissions = true;
_createOptions.PrimaryObject = true;
_createOptions.SchemaQualify = true;
_createOptions.SchemaQualifyForeignKeysReferences = true;
_createOptions.ScriptDrops = false;
_createOptions.Triggers = true;

table.Script(_createOptions)
---------------------------------

Here are the parts I'm missing:

---------------------------------
ALTER TABLE [dbo].[PERSON] ADD
    CONSTRAINT [DF_PERSON_FirstName] DEFAULT ('FIRST') FOR [FirstName] GO

setuser
GO

EXEC sp_bindrule N'[dbo].[RULE_BOOLEAN]', N'[PERSON].[Flag]' GO

EXEC sp_bindefault N'[dbo].[DEF_NO]', N'[PERSON].[Flag]' GO

EXEC sp_bindefault N'[dbo].[DEF_ID]', N'[PERSON].[OriginID]' GO

EXEC sp_bindefault N'[dbo].[DEF_ID]', N'[PERSON].[OwnerID]' GO

EXEC sp_bindefault N'[dbo].[DEF_TODAY_UTC]', N'[PERSON].[Timestamp]' GO

EXEC sp_bindrule N'[dbo].[RULE_BOOLEAN]', N'[PERSON].[VerifySSN]' GO

EXEC sp_bindefault N'[dbo].[DEF_NO]', N'[PERSON].[VerifySSN]' GO

EXEC sp_bindrule N'[dbo].[RULE_BOOLEAN]', N'[PERSON].[WorkBadAddress]' GO

EXEC sp_bindefault N'[dbo].[DEF_NO]', N'[PERSON].[WorkBadAddress]' GO

setuser
GO
---------------------------------

Thanks.
Scott C.

AddThis Social Bookmark Button