我试图在sql中创建一个表,但我错过了一个关键字,无法找到如何解决它

时间:2017-04-01 12:44:36

标签: sql oracle ddl

我正在尝试在SQL中创建一个表,但我错过了一个关键字,我无法弄清楚如何修复它:

CREATE TABLE Attendance_of_employee
(
  supervisior VARCHAR(30) DEFAULT 'NONE',
  arrival double NOT NULL,
  shift_end double NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  ID_record VARCHAR(30) NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);

Error report -
SQL Error: ORA-00905: chýbajúce kľúčové slovo
00905. 00000 -  "missing keyword"
*Cause:    
*Action:

2 个答案:

答案 0 :(得分:2)

在Oracle中,您通常使用number表示数字值,使用varchar2()表示字符串。我总是将主键作为表中的第一列。所以:

CREATE TABLE Attendance_of_employee (
  ID_record VARCHAR2(30) NOT NULL,
  supervisior VARCHAR2(30) DEFAULT 'NONE',
  arrival number NOT NULL,
  shift_end number NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);

Here是Rextester中的链接(没有外键关系,因为未定义EmployeeTAB)。

答案 1 :(得分:1)

使用双精度而不是双精度。

CREATE TABLE Attendance_of_employee( supervisior VARCHAR(30) DEFAULT 'NONE', 
arrival double precision NOT NULL, 
shift_end double precision NOT NULL, date_time DATE NOT NULL, 
worked_hours INT NOT NULL, 
ID_record VARCHAR(30) NOT NULL, employeeID INT NOT NULL, PRIMARY KEY (ID_record), 
FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID) );