Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    35

    Unanswered: Foreign Key Relationship - Table Designer

    I want to enforce Foreign Key Integrity on two tables. I followed the article below.

    How to: Create Relationships Between Tables (Visual Database Tools)

    After creating the Relationship, I am still able to populate values in foreign key table with invalid data.

    Maybe there is another step to do to force an error when foreign key values don't exist in the reference table?

    As always, I will continue to research, Thanks

    Database = SQL Server 2005

  2. #2
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    Don't waste your time with the table designer. You can create a foreign key with just one step:

    ALTER TABLE tbl1 ADD CONSTRAINT fk1 FOREIGN KEY (col1) REFERENCES tbl2 (col1);

    You can find the full syntax in Books Online.

  3. #3
    Join Date
    Jan 2009
    Posts
    35
    Thanks dp.

    I just wanted to see how the Table Designer worked. Doesn't seem to do what is needed.

  4. #4
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    script everything. you will probably need to apply changes in more than 1 place, right? The problem with the grapgpical tools has always been they obfuscate what is really happening.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  5. #5
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by Thrasymachus
    script everything. you will probably need to apply changes in more than 1 place, right? The problem with the grapgpical tools has always been they obfuscate what is really happening.
    Yep.

    I typically always script things, I am just new to SQL Server 2005 and wanted to see how it works.

    Unfortunately, we don't have a "true" DBA at my current job, so I am always trying to find out what the "best practice" is for doing something in SQL Server 2005.

    Thanks

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Best practice: script it.

    If you want to see what the GUI is doing, fire up profiler and see what it says is going on as you follow that tutorial.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •