Sergio Tapia
Sergio Tapia

Reputation: 41128

What is wrong with this SQL statement?

I'm trying to create this table and I want to gauge my eyes out. What is wrong with it? I get an error: "Incorrect syntax near PLAN"

create table Instrumentos(
ID int primary key,
IDSeguimiento int foreign key references Seguimiento(ID),
GuiaDocente bit,
GuiaDocenteObservacion varchar(200),
GuiaAlumno bit,
GuaiAlumnoObservacion varchar(200),
Plan bit,
PlanObservacion varchar(200),
RegistroNotas bit,
RegistroNotasObservacion varchar(200),
PlanificacionClases bit,
PlanificacionClasesObservacion varchar(200),
Limat bit,
LimatObservacion varchar(200),
ProyectoFinal bit,
ProyectoFinal varchar(200),
Practicos bit,
PracticosObservacion varchar(200),
Portfolio bit,
PortfolioObservacion varchar(200)
)

Upvotes: 2

Views: 461

Answers (6)

Remy Lebeau
Remy Lebeau

Reputation: 595652

PLAN is a reserved keyword. Depending on which SQL engine you are using, you will have to escape that column name using either quotations or brackets, ie:

"Plan" bit

Or

[Plan] bit

And also do so in any queries, ie:

INSERT INTO Instrumentos(..., [Plan], ...) VALUES (...)

Or:

INSERT INTO Instrumentos(..., "Plan", ...) VALUES (...)

Upvotes: 1

bobs
bobs

Reputation: 22184

Two problems:

  1. Plan is SQL Server reserved word.
  2. ProyectoFinal column name is used twice.

Upvotes: 4

Matt
Matt

Reputation: 2815

Plan is a reserved word. If you really want to use it, and I advise against it, you would need to enclose it in escape characters.

Upvotes: 1

Paddyslacker
Paddyslacker

Reputation: 1880

Plan is a SQL reserved word.

Upvotes: 1

duffymo
duffymo

Reputation: 308743

Plan is probably a SQL keyword (e.g, "EXPLAIN PLAN").

Either escape the column name or change it.

Upvotes: 1

Jay
Jay

Reputation: 57899

PLAN is a reserved keyword.

Change the name or use the appropriate escape for your server type. For MSSQL, I think you'd use [Plan], but you'll have to do that any time you write a query/procedure/etc.

Upvotes: 7

Related Questions