Skip to content
Advertisement

Wrong SQL Syntax; Incorrect syntax near ‘)’

I’m using Microsoft SQL Server Management Studio that’s hooked up to an Azure SQL database; usually, I’m used to using Oracle (It’s just a rookie mistake I guess). What exactly am I doing wrong? These are the error messages that I’m getting:

Msg 102, Level 15, State 1, Line 11
Incorrect syntax near ‘)’.

Msg 102, Level 15, State 1, Line 42
Incorrect syntax near ‘)’.

Msg 102, Level 15, State 1, Line 54
Incorrect syntax near ‘)’.

Msg 102, Level 15, State 1, Line 66
Incorrect syntax near ‘)’.

This is my code:

Advertisement

Answer

WHAT other table/column(s) do these foreign key reference?? You need to provide that info!

Also, those references have to match a whole, complete primary key of another table – you cannot reference only parts of a (composite) primary key. The names, order, and datatype of the columns in the foreign key must exactly match the primary key of the table being referenced.

I didn’t find any other table in your sample shown that has a primary key that’s made up from (CatalogYearID, MajorID) – so this reference here (and some of the others, too) is very unclear …..

And as a side note: I would strongly recommend to explicitly name your constraints:

That makes it just soooo much easier to reference those constraints if you ever need to e.g. disable or drop them.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement