You are currently viewing the BOOK: Beginning VB.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Rather than build the SQL database by hand, I'm attempting to run the SQL script. My issue is that I'm receiving several syntax errors of the form below:
Server: Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'PRIMARY'.
The line of code in the sql which causes the above error is marked in red below:
---------------------------------------------------------------------
-- Primary Keys
---------------------------------------------------------------------
ALTER TABLE GroupProjects WITH NOCHECK ADD
CONSTRAINT PK_GroupProjects PRIMARY KEY CLUSTERED
(
GroupProjectID
) ON PRIMARY
GO
----------
Can anyone offer any advice? I've not used sql scripts much before - and google could not help.
After creating the tables, I let SQL Server generate the script. I have noticed, using SQL Server 2000, that sometimes this causes an error. I believe it may have something to do with how SQL Server is installed (e.g. options selected). However I have not really had the time to dig into the problem deeper.
PRIMARY is the name of your filegroup. You can also use DEFAULT. The problem that you're seeing is that both PRIMARY and DEFAULT are already SQL keywords. Replace PRIMARY with [PRIMARY] and all of your scripts will work fine.
I suspect that you used the scripting tool to generate your SQL but then did a search/replace to knock off the [s and ]s, causing your problem.