Generating scripts for FKs and Indexes only

  • I want to generate a create script for all Foreign Keys in a single database, then another for all indexes other than PKs and unique constraints. 

    The scripts wizard doesn't seem to allow this to happen unless the script contains the table create statement itself.

    I've always been under the impession that any wizard action that acts on a database can be replicated in T-SQL.  Can the above actions be handled with T-SQL?

    Joel

    Takauma

  • HI Joel,

    This will give you all teh triggers

    SELECT Text

    FROM sysobjects o

    INNER JOIN syscomments c

    ON o.ID = c.ID

    WHERE xType = 'tr'

    I'll start looking into the others for you now as well.

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Sorry Joel,

    I got very confused there for a second.

    You didn't ask for anything to do with triggers my mistake

    😉

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Joel -

    I find this request unusual, and it sounds like you are trying to correct an earlier false assumption about the source database, which resulted in copying the table structures, but only the PKs and unique constraints and none of the other pieces.

    It would be done easiest with 3rd party tools, but you could either take the entire scripts and edit out what you don't need, or simply build a new instance with all the rules and then port the data over (use a backup and restore to the new instance)?

    It may make more sense to describe your situation and define the objective you are trying to accomplish. Yes, what you ask for would result in an elegant, straightforward, and efficient solution IF I've correctly surmised the problem definition. But the time required to create such a solution may not be worth the 'brute force' technique.

    What comes to mind, in 3rd party tools, would be a comparison tool that does script building to correct missing components in the target database.

    Good hunting!

    Steve

Viewing 4 posts - 1 through 3 (of 3 total)

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