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. syntax error in CONSTRAINT clause

syntax error in CONSTRAINT clause

Scheduled Pinned Locked Moved Database
databasecsharphelptutorialquestion
2 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
    Megidolaon
    wrote on last edited by
    #1

    I'm trying to use C# to add a column to an MS Access database, but I'm having trouble with the syntax. My SQL string amounts to something like this: ALTER TABLE t_customer ADD person_id integer CONSTRAINT FK_person_id FOREIGN KEY (person_id) REFERENCES t_person (person_id) I can't find any difference to the MSDN example syntax. Can you tell me where the error is? Thanks!

    L 1 Reply Last reply
    0
    • M Megidolaon

      I'm trying to use C# to add a column to an MS Access database, but I'm having trouble with the syntax. My SQL string amounts to something like this: ALTER TABLE t_customer ADD person_id integer CONSTRAINT FK_person_id FOREIGN KEY (person_id) REFERENCES t_person (person_id) I can't find any difference to the MSDN example syntax. Can you tell me where the error is? Thanks!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Megidolaon wrote:

      My SQL string amounts to something like this

      "Something like that" should work.

      Megidolaon wrote:

      Can you tell me where the error is?

      Not without seeing your code, but I could do an educated guess. You're referring to this[^] example? The example on that page lists this code;

      ' Add a foreign key to the Orders table.
      dbs.Execute "ALTER TABLE Orders " _
      & "ADD CONSTRAINT OrdersRelationship " _
      & "FOREIGN KEY (EmployeeID) " _
      & "REFERENCES Employees (EmployeeID);"

      Are you concatenating strings the same way? If so, check the resulting string - it may be missing the space at the end of each line; between "Orders" and "ADD", between "OrdersRelationShip" and "FOREIGN" and between ")" and "REFERENCES".

      I are Troll :suss:

      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