Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Posts
    25

    Unanswered: Relationships between table

    Hi,

    Is it possible to create a relationship between two tables on two fields using a code? If yes, small example would be great.

    Thanks
    DJ

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what does "using a code" mean?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    May 2004
    Posts
    25
    By "Using code" I ment using Visual Basic - commands etc.

  4. #4
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    There is always DoCmd.RunSQL followed by whatever SQL command you wish to use to accomplish the intended task .
    Darasen

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    oh, i get it, you mean, can you declare a relationship between two tables using data definition language or DDL, which is a subset of SQL

    yes, you can


    see ACC2000: Create and Drop Tables and Relationships Using SQL DDL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    May 2004
    Posts
    25
    Hi r937,

    would it be possible to write a small example how to do that. Just for two tables related on two fields.

    Thank you DJ

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    did you read that page?

    here's the example they used --
    After you create both tables, running the following query creates a one- to-many relationship between Table1 and Table2, with Table1 as the primary side of the relationship:
    Code:
    ALTER TABLE Table2 
    ADD CONSTRAINT Relation1 
    FOREIGN KEY ([Id]) REFERENCES Table1 ([Id])
    so to make the relationship on two columns, you would put the two columns where the [Id] column is in their example
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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