views:

227

answers:

7

I get the following error from the SQL Script I am trying to run:

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

This is the SQL script:

IF NOT EXISTS (SELECT * 
                 FROM dbo.sysobjects 
                WHERE id = OBJECT_ID(N'[dbo].HDDB_DataSource]') 
                  AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[HDDB_DataSource](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [Name] [nvarchar](255) NOT NULL,
 [Type] [nvarchar](50) NOT NULL,
 [XmlFileName] [nvarchar](255) NULL,
 [ConnectionString] [nvarchar](255) NULL),
 CONSTRAINT [PK_DataSource] PRIMARY KEY CLUSTERED 
(
 [ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END

I am using SQL Server 2005 if that helps.

Jeff

+1  A: 

You appear to have duplicate lines here:

) ON [PRIMARY]
) ON [PRIMARY]

so the braces are not balanced.

Rob Osborne
They're not duplicates nor a syntax error. First one is filegroup for the primary key and second is the filegroup for the table.
DyingCactus
+5  A: 

Remove the ")" in "[ConnectionString] nvarchar NULL),"

dbemerlin
+1 you can paste the OP's code into SSMS and click on the "parse" check icon on the toolbar and get the error message. If you remove the ")" as described in this answer, and repeat the "parse" (or actually run it and create the table) the error goes away and the code runs.
KM
This worked thank you :)
jeffreyshek
+3  A: 

Get rid of the close paren at the end of the ConnectionString column line before the comma and it should work

Rob Packwood
+1  A: 

Duplicates

) ON [PRIMARY]
) ON [PRIMARY]
gmcalab
They're not duplicates nor a syntax error. First one is filegroup for the primary key and second is the filegroup for the table.
DyingCactus
@DyingCactus, good point, the extra ) threw me off. +1
gmcalab
+2  A: 

Remove ), after the last field (before the constraint).

Guffa
+3  A: 

See, the extraneous ) at the end of this line?

 [ConnectionString] [nvarchar](255) NULL),
mjv
A: 

Remove , from last row [ConnectionString] nvarchar NULL),

Nakul Chaudhary