locked
Error Msg 156 RRS feed

  • Question

  • I can't find the syntax error that SQL says I have. Can somebody hellp me with a fresh pair of eyes please?

    I keep getting the following msg

    Msg 156, Level 15, State 1, Line 12
    Incorrect syntax near the keyword 'CONSTRAINT'

     

    Here is my code:

    CREATE TABLE [dbo].[Application2](
        [ApplicationID] [char](10) NOT NULL,
        [Cost] [money] NULL,
        [Size] [char](10) NULL,
        [Name] [char](30) NULL,
        [RevDate] [datetime] NULL,
        [VerNum] [char](10) NULL,
        [AuthorID] [char](10) NULL,

    CONSTRAINT [PK_Application2] PRIMARY KEY ([ApplicationID])   

    CONSTRAINT [FK_Application2_Author] FOREIGN KEY([AuthorID])
               
                REFERENCES [dbo].[Author] ([AuthorID])

    )

    Tuesday, August 24, 2010 12:40 AM

Answers

  • hi,

    just a comma :)

    SET NOCOUNT ON;
    USE tempdb;
    GO
    CREATE TABLE [dbo].[Author] (
     [AuthorID] [char](10) NOT NULL PRIMARY KEY
     );
     
    CREATE TABLE [dbo].[Application2](
        [ApplicationID] [char](10) NOT NULL,
        [Cost] [money] NULL,
        [Size] [char](10) NULL,
        [Name] [char](30) NULL,
        [RevDate] [datetime] NULL,
        [VerNum] [char](10) NULL,
        [AuthorID] [char](10) NULL,

    CONSTRAINT [PK_Application2] PRIMARY KEY ([ApplicationID]),

    CONSTRAINT [FK_Application2_Author] FOREIGN KEY([AuthorID])
               
                REFERENCES [dbo].[Author] ([AuthorID])

    )
    GO
    DROP TABLE [dbo].[Application2], [dbo].[Author];

    regards

     


    http://www.asql.biz - DbaMgr2k - DbaMgr and further SQL Tools http://www.hotelsole.com/ - http://www.hotelsolericcione.de
    • Proposed as answer by YoYo Yu Wednesday, August 25, 2010 9:50 AM
    • Marked as answer by YoYo Yu Monday, August 30, 2010 5:03 AM
    Tuesday, August 24, 2010 12:45 AM

All replies

  • hi,

    just a comma :)

    SET NOCOUNT ON;
    USE tempdb;
    GO
    CREATE TABLE [dbo].[Author] (
     [AuthorID] [char](10) NOT NULL PRIMARY KEY
     );
     
    CREATE TABLE [dbo].[Application2](
        [ApplicationID] [char](10) NOT NULL,
        [Cost] [money] NULL,
        [Size] [char](10) NULL,
        [Name] [char](30) NULL,
        [RevDate] [datetime] NULL,
        [VerNum] [char](10) NULL,
        [AuthorID] [char](10) NULL,

    CONSTRAINT [PK_Application2] PRIMARY KEY ([ApplicationID]),

    CONSTRAINT [FK_Application2_Author] FOREIGN KEY([AuthorID])
               
                REFERENCES [dbo].[Author] ([AuthorID])

    )
    GO
    DROP TABLE [dbo].[Application2], [dbo].[Author];

    regards

     


    http://www.asql.biz - DbaMgr2k - DbaMgr and further SQL Tools http://www.hotelsole.com/ - http://www.hotelsolericcione.de
    • Proposed as answer by YoYo Yu Wednesday, August 25, 2010 9:50 AM
    • Marked as answer by YoYo Yu Monday, August 30, 2010 5:03 AM
    Tuesday, August 24, 2010 12:45 AM
  • The extra comma is here

    [AuthorID] [char](10) NULL,



    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Tuesday, August 24, 2010 1:20 AM