sql script error on varchar and exit under mysql
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 */
);
CRE开发者_StackOverflow中文版ATE 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;
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;
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 */);
精彩评论