问题
Possible Duplicate:
I have mistake in database
create table Ticket (
ticket_id integer not null primary key,
AirlineName varchar not null,
CustomerName varchar,
fromCity varchar,
toCity varchar,
fltNo integer,
TicketDate date,
Dtime TIME,
Atime time,
price integer);
Please help me, I can't find the error. the program is my sql, and this is the error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null, CustomerName varchar, fromCity varchar, toCity varchar, fltNo inte' at line 3
回答1:
Now that I know it's MySQL:
Your varchars should have lengths (and phpMyAdmin appears to use INT instead of integer, but both seem to be valid)
CREATE TABLE Ticket(
ticket_id INT PRIMARY KEY ,
AirlineName VARCHAR( 255 ) NOT NULL ,
CustomerName VARCHAR( 255 ) ,
fromCity VARCHAR( 255 ) ,
toCity VARCHAR( 255 ) ,
fltNo INT,
TicketDate DATE,
Dtime TIME,
Atime TIME,
price INT
);
回答2:
Possible solution...
In your case, you use mysql, so this is the correct syntax.
Remember to put the VARCHAR length...
create table Ticket (
ticket_id int not null,
AirlineName varchar(255) not null,
CustomerName varchar(255),
fromCity varchar(255),
toCity varchar(255),
fltNo integer,
TicketDate date,
Dtime TIME,
Atime time,
price int,
primary key (ticket_id)
);
来源:https://stackoverflow.com/questions/11675565/i-cant-solve-error-in-database