PostgreSQL表不存在

时间:2017-10-06 07:13:32

标签: sql postgresql

drop table Employee;   

 CREATE TABLE Employee
    (   EmployeeID integer,
        FirstName varchar(24),
        LastName varchar(24),
        Email varchar(48),
        PhoneNumber varchar(12),
        HotelID integer
        PRIMARY KEY (EmployeeID),
    );

    INSERT INTO Employee VALUES (1, ‘James’, ‘Jenkins’, ‘jj@gmail.com’, ’0412181111’, 1);
    INSERT INTO Employee VALUES (22, ‘Roy’, ‘Bond’, ‘jb@gmail.com’, ‘0418246192’, 1);
    INSERT INTO Employee VALUES (14, ‘Rachel’, ‘Green’, ‘rg@gmail.com’, ‘0468129367’, 1);
    INSERT INTO Employee VALUES (96, ‘Eddard’, ‘Stark’, ‘es@gmail.com’, ‘0458192716’, 1);
    INSERT INTO Employee VALUES (77, ‘Anna’, ‘Nguyen’, ‘an@gmail.com’ , ‘0418238694’, 1);

错误:“psql:employee:1:错误:表”员工“不存在”

可以修复错误的方法是什么?

如果有人想看看,请链接到整个文档:https://docs.google.com/document/d/1r4E7yz4XJxLmO3rmkH4YBVOGfYN5PkhcDSJUyuy7qxw/edit?usp=sharing

2 个答案:

答案 0 :(得分:0)

在声明主键之前,您的create语句缺少逗号(,)。因此表格没有被创建。这个:

CREATE TABLE Employee
(   EmployeeID integer,
FirstName varchar(24),
LastName varchar(24),
Email varchar(48),
PhoneNumber varchar(12),
HotelID integer,
PRIMARY KEY (EmployeeID),
FOREIGN KEY (HotelID) REFERENCES Hotel
);

答案 1 :(得分:0)

当您尝试在上面的代码段上运行时,可能尚未在数据库中创建表Employee。在删除表或存储过程或函数之前,始终要进行IF EXISTS检查。

你的drop查询应该是。

drop table if exists `Employee`;