I cant solve error in database [duplicate]

耗尽温柔 提交于 2019-12-25 18:25:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!