Manage ForeignKey with SMO in Vb.net

  • hi all!

    Sorry for my bad english, but i have some difficult to write.

    Well....

    I need work with Foreignkey and i don't have find any information about this. I´d like some help if is possible.

    I have a DataBase (SQL SERVER 2005) with 10 (ten) tables and i need to truncate some tables before insert data values. In 6 (six) tables i have a foreignkey and i have drop foreignkey to can drop the table and after that rebuild a foreign key.

    I working with a Visual Studio 2008 and Vb.Net language and i have a logic programming to do this, but i don't know how make this possible.

    Can anyone help me, please ?

    Tks

    for all.

  • This should get you started:

    'truncate:

    With Table

    'disable the FKeys:

    For Each FK As ForeignKey In .ForeignKeys

    FK.IsEnabled = False

    Next

    .TruncateData()

    're-enable the FKeys:

    For Each FK As ForeignKey In .ForeignKeys

    FK.IsEnabled = True

    Next

    End With

    'Drop:

    With Table

    For Each FK As ForeignKey In .ForeignKeys

    FK.Drop()

    Next

    .Drop()

    End With

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply