Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Foreign Keys ease SQL statements?

Foreign Keys ease SQL statements?

Scheduled Pinned Locked Moved Database
databasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, I'm creating a Win Form that uses a MS Access Database. I'm new to database programming and wanted to know what advantages, besides referential integrity, is there to creating a Foreign Key? I'm wondering if creating a Foreign Key helps me with SQL statements in my code? Or would creating Foreign Keys not change SQL statements like this: AND Products.CustomerID=Customers.CustomerID thanks, Ron

    G 1 Reply Last reply
    0
    • M myNameIsRon

      Hi, I'm creating a Win Form that uses a MS Access Database. I'm new to database programming and wanted to know what advantages, besides referential integrity, is there to creating a Foreign Key? I'm wondering if creating a Foreign Key helps me with SQL statements in my code? Or would creating Foreign Keys not change SQL statements like this: AND Products.CustomerID=Customers.CustomerID thanks, Ron

      G Offline
      G Offline
      Gerald Schwab
      wrote on last edited by
      #2

      I can't think of another reason besides referential integrity. Foreign keys are constraints and do not change SQL statements. They just guarantee that Products.CustomerID will match the CustomerID in the Customers table. In other words, you shouldn't be able to delete Customer 1 from the Customers table if Customer 1 exists in the Products table.

      M 1 Reply Last reply
      0
      • G Gerald Schwab

        I can't think of another reason besides referential integrity. Foreign keys are constraints and do not change SQL statements. They just guarantee that Products.CustomerID will match the CustomerID in the Customers table. In other words, you shouldn't be able to delete Customer 1 from the Customers table if Customer 1 exists in the Products table.

        M Offline
        M Offline
        myNameIsRon
        wrote on last edited by
        #3

        Thanks Gerald, I thought that, but wanted to ask anyway. Ron

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups