Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
纠正sql代码中的错误_Sql_Database_Oracle - Fatal编程技术网

纠正sql代码中的错误

纠正sql代码中的错误,sql,database,oracle,Sql,Database,Oracle,我是这个网站的新手,我希望我能以正确的方式提问 -- Create a Database table to represent the "FACT" entity. CREATE TABLE FACT ( Time_id DATE NOT NULL, Area_id INTEGER NOT NULL, Reported_crime_id INTEGER NOT NULL, Crime_status

我是这个网站的新手,我希望我能以正确的方式提问

-- Create a Database table to represent the "FACT" entity. 
CREATE TABLE FACT 
  ( 
     Time_id           DATE NOT NULL, 
     Area_id           INTEGER NOT NULL, 
     Reported_crime_id INTEGER NOT NULL, 
     Crime_status      VARCHAR(8) NOT NULL, 
     no_of_crime       INTEGER NOT NULL, 
     Max_crime         INTEGER NOT NULL, 
     Avg_crime         INTEGER NOT NULL, 
     Min_crime         INTEGER NOT NULL, 
     date_reported     DATE NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "FACT". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_fact PRIMARY KEY (Time_id, Area_id, Reported_crime_id, 
     Crime_status) 
  ); 

-- Create a Database table to represent the "Crime_Dim" entity. 
CREATE TABLE Crime_Dim 
  ( 
     REPORTED_CRIME_ID INTEGER NOT NULL, 
     CRIME_TYPE_Desc   VARCHAR(50), 
     DATE_REPORTED     DATE NOT NULL, 
     Crime_type_id     INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "Crime_Dim". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_crime_dim PRIMARY KEY (REPORTED_CRIME_ID) 
  ); 

-- Create a Database table to represent the "Location_Dim" entity. 
CREATE TABLE Location_Dim 
  ( 
     AREA_ID   INTEGER NOT NULL, 
     AREA_Name VARCHAR(30) NOT NULL, 
     Area_code INTEGER NOT NULL, 
     Force_id  INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "Location_Dim". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_location_dim PRIMARY KEY (AREA_ID) 
  ); 

-- Create a Database table to represent the "Time_Dim" entity. 
CREATE TABLE Time_Dim 
  ( 
     Time_id  INTEGER NOT NULL, 
     day_id   INTEGER NOT NULL, 
     Month_id INTEGER NOT NULL, 
     Year     INTEGER, 
     -- Specify the PRIMARY KEY constraint for table "Time_Dim". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_time_dim PRIMARY KEY (Time_id) 
  ); 

-- Create a Database table to represent the "Reported_crime_dim" entity. 
CREATE TABLE Reported_crime_dim 
  ( 
     Crime_status  VARCHAR(20) NOT NULL, 
     Date_reported DATE NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "Reported_crime_dim". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_reported_crime_dim PRIMARY KEY (Crime_status) 
  ); 


-- i.e. tables may be referenced before they have been created.  This method is therefore safer.
-- Alter table to add new constraints required to implement the "FACT_Time_Dim" relationship 
-- This constraint ensures that the foreign key of table "FACT" 
-- correctly references the primary key of table "Time_Dim" 
ALTER TABLE FACT 
  ADD CONSTRAINT fk1_fact_to_time_dim FOREIGN KEY(Time_id) REFERENCES Time_Dim( 
  Time_id) ON DELETE RESTRICT ON UPDATE RESTRICT; 

-- Alter table to add new constraints required to implement the "FACT_Location_Dim" relationship
-- This constraint ensures that the foreign key of table "FACT" 
-- correctly references the primary key of table "Location_Dim" 
ALTER TABLE FACT 
  ADD CONSTRAINT fk2_fact_to_location_dim FOREIGN KEY(AREA_ID) REFERENCES 
  Location_Dim(AREA_ID) ON DELETE RESTRICT ON UPDATE RESTRICT; 

-- Alter table to add new constraints required to implement the "FACT_Crime_Dim" relationship
-- This constraint ensures that the foreign key of table "FACT" 
-- correctly references the primary key of table "Crime_Dim" 
ALTER TABLE FACT 
  ADD CONSTRAINT fk3_fact_to_crime_dim FOREIGN KEY(REPORTED_CRIME_ID) REFERENCES 
  Crime_Dim(REPORTED_CRIME_ID) ON DELETE RESTRICT ON UPDATE RESTRICT; 

-- Alter table to add new constraints required to implement the "FACT_Reported_crime_dim" relationship
-- This constraint ensures that the foreign key of table "FACT" 
-- correctly references the primary key of table "Reported_crime_dim" 
ALTER TABLE FACT 
  ADD CONSTRAINT fk4_fact_to_reported_crime_dim FOREIGN KEY(Crime_status) 
  REFERENCES Reported_crime_dim(Crime_status) ON DELETE RESTRICT ON UPDATE 
  RESTRICT; 
-------------------------------------------------------------- 
-- End of DDL file auto-generation 
-------------------------------------------------------------- 
​ 有人能帮我纠正上面sql代码中的错误吗?当我运行最后几段代码中提到的代码时,我需要创建约束以防止事实表中的外键,并将它们关联回它们的原始表(如果我正确的话)。。。 是否有人可以更正代码并让我知道plz

下面,您必须在删除限制时删除
,在更新限制时删除

Oracle中没有这样的选项。

噢。我的。墙属于代码。你有什么错误?你能告诉我们这些错误吗?更具体地说,你希望代码做什么,它的作用是什么呢?0.01更改表事实添加约束fk1_事实_到时间_维度外部ORA-00905:缺少关键字-7 0.01更改表事实添加约束fk2_事实_到位置_维度ORA-00905:缺少关键字-8 0.01更改表事实添加约束fk3_事实_到犯罪_维度ORA-00905:缺少关键字-9 0.01更改表事实添加约束fk4_FACT_to_Reported_crime_d ORA-00905:缺少关键字这是我运行代码时遇到的错误。这有什么意义吗?谢谢你们的回复。Dan我想运行代码来创建四个表和一个事实表。我正在尝试删除/更正代码中的错误。请注意在Qsee中创建的usng forward engineering代码