Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

How to: Create Matching Foreign and Primary Keys (Visual Database Tools)

Updated: 12 December 2006

When you copy a column from one table to another table, the column name and many of the other properties you defined for that column in the original table are copied to the new location. You can copy column properties from a primary key column to a foreign key column if you want to relate the two columns. Related columns must have the same data type (or data types that can be related) and length.

  1. In Object Explorer, right-click the table with primary key columns you want to copy and click Design (Modify in SP1 or earlier). Do the same for the table into which you want to copy the columns as foreign keys.

    The tables open in Table Designer.

  2. Click the tab for the table with the columns you want to copy.

  3. Select the primary key columns that you want to copy.

    Primary key columns are indicated by a key symbol in their row selector.

  4. From the Edit menu, click Copy.

  5. Click the tab for the table into which you want to copy the columns.

  6. Select the column you want to follow the inserted columns and from the Edit menu, click Paste.

  7. Right-click the foreign key table and click Relationships on the shortcut menu.

    The Foreign Key Relationships dialog box opens.

  8. Create a relationship between the primary key and foreign key columns.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.