tags:

views:

24

answers:

2

This sql script gives me error at the VARCHAR and EXIT;. I try to run it under MySQL console. May I know how to solve this?

CREATE TABLE Solution (
SolutionKey    INT NOT NULL, /* PRIMARY KEY (SolutionKey), */
FeatureKey    VARCHAR(100),    /* +++ Foreign key missing here */
Value    VARCHAR(4000)
);


CREATE TABLE InactiveContext (
CaseKey    INT NOT NULL,     /* PRIMARY KEY (CaseKey), */
Context    VARCHAR(100)
);

CREATE TABLE Class (
FeatureKey    VARCHAR(100),   /* +++ Foreign key missing here */
ClassName    VARCHAR(1000)
);


CREATE TABLE ExtraData (
Key    VARCHAR(1000),
Value    VARCHAR(1000),
FeatureKey   VARCHAR(100)    /* +++ Foreign key missing here */
);


CREATE TABLE ProblemCCBRFeatureSpec (
FeatureKey    VARCHAR(100),    /* +++ Foreign key missing here */
Question    VARCHAR(1000)
);


CREATE TABLE HashMap (
CollectionID    INT,       /* +++ Foreign key missing here */
Key    VARCHAR(1000),
Value    VARCHAR(1000)
);


CREATE TABLE HashSet (
CollectionID    INT,       /* +++ Foreign key missing here */
Value    VARCHAR(1000)
);


CREATE TABLE Constants (
ConstantName    VARCHAR(1000),    /* +++ Must be a primary key ??? */
ConstantValue    VARCHAR(4000)
);

COMMIT;
EXIT;
+1  A: 

It is because you are using reserved word for createing tables, such as

Key and Value,

Try to change this for others column Name

    CREATE TABLE ExtraData (Key    VARCHAR(1000),Value  
  VARCHAR(1000),FeatureKey   VARCHAR(100)  
  /* +++ Foreign key missing here */);
Necronet
+1  A: 

VALUE and KEY are MySQL reserved words which you are using as column names.

To fix this you can either choose different names for these fields or you enclose them in back-ticks(`) every time you use them in the query.

CREATE TABLE ExtraData (
`Key`    VARCHAR(1000),
`Value`    VARCHAR(1000),
FeatureKey   VARCHAR(100)  
);

Later when you want to fetch data from the table you'll have to use quotes again as:

SELECT `Key`, `Value` from ExtraData;
codaddict
ok, it runs now. but at the EXIT syntax, still error :(
karikari
Can you tell us the error?
codaddict
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to use near 'EXIT'
karikari
You can remove the `EXIT` from the script.
codaddict
it works without the EXIT. but will it affect?
karikari
No it does not, the end of the file is an implicit exit.
codaddict