Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    21

    Unanswered: Incorrect Syntax Error When Adding a foreign key

    ALTER TABLE cost
    ADD CONSTRAINT FK_cost,
    FOREIGN KEY cost_category_id
    REFERENCES cost_category(cost_category_id)

    both tables have the cost_category_id columns and exist, but I keep getting this error and I don't know why.

    Msg 102, Level 15, State 1, Line 3
    Incorrect syntax near 'cost_category_id'.

    EDIT: SQL Server 2005

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Code:
    ALTER TABLE cost
    ADD CONSTRAINT FK_cost
    FOREIGN KEY (cost_category_id)
    REFERENCES cost_category(cost_category_id)
    thank you. drive through.
    “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.

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Code:
    ALTER TABLE [dbo].[<TableName>]  
    	WITH CHECK ADD  CONSTRAINT [FK_<TableName>] FOREIGN KEY([<ColumnName>])
    REFERENCES [dbo].[<ParentTableName>] ([<ParentColumnName>])
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Sep 2009
    Posts
    21
    oh wow, one set of parenthesis threw me off.

    Thanks

Posting Permissions

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