表格或视图不存在错误,原因不明

时间:2017-03-26 20:10:51

标签: sql oracle

DROP TABLE BASIC_USER;
DROP TABLE ADMIN_USER;
DROP TABLE EQUIPMENT;
DROP TABLE CAVE;
DROP TABLE DUNGEON;
DROP TABLE ADVENTURE;
DROP TABLE AUTHOR;
DROP TABLE CHARACTER_GROUP;
DROP TABLE MY_CHARACTER;
DROP TABLE MY_USER;

CREATE TABLE MY_USER (
  user_ID int NOT NULL,
  nick varchar(255) NOT NULL,
  date_of_registration date DEFAULT current_date,
  first_name varchar(255) NOT NULL,
  last_name varchar(255),
  email varchar(255) UNIQUE, 
  age int NOT NULL,
  user_location varchar(255),
  finished_adventures int DEFAULT 0 NOT NULL,
  PRIMARY KEY(user_ID)
);

CREATE TABLE MY_CHARACTER (
  character_ID int NOT NULL,
  owner_ID int REFERENCES MY_USER(user_ID),
  char_name varchar(255) NOT NULL,
  race varchar(255) NOT NULL,
  char_class varchar(255) NOT NULL,
  char_rank int NOT NULL,
  hp int NOT NULL,
  status int NOT NULL,
  CHECK (char_rank <= 99 AND char_rank >= 0),
  CHECK (hp <= 100 AND hp >= 0),
  CHECK (status <= 1 AND status >= 0),
  PRIMARY KEY(character_ID)
);

CREATE TABLE EQUIPMENT (
  equipment_ID int NOT NULL,
  owner_ID int REFERENCES MY_CHARACTER(character_ID),
  equipment_name varchar(255) NOT NULL,
  equipment_type varchar(255) NOT NULL,
  attack int NOT NULL,
  defense int NOT NULL,
  PRIMARY KEY(equipment_ID)
);

CREATE TABLE DUNGEON (
  dungeon_ID int NOT NULL,
  dungeon_location varchar(255),
  dungeon_difficulty int NOT NULL,
  goal varchar(2500),
  status int NOT NULL,
  dungeon_creator_ID int REFERENCES AUTHOR(author_ID),
  CHECK (dungeon_difficulty <= 5 AND dungeon_difficulty >= 0),
  PRIMARY KEY(dungeon_ID)
);

CREATE TABLE ADVENTURE (
  adventure_ID int NOT NULL,
  adventure_name varchar(255) NOT NULL,
  adventure_location varchar(255) NOT NULL,
  adventure_difficulty int NOT NULL,
  participant_ID int REFERENCES CHARACTER_GROUP(chargroup_ID),
  adventure_goal varchar(2500),
  creator_ID int REFERENCES AUTHOR(author_ID),
  PRIMARY KEY (adventure_ID)
);

CREATE TABLE CHARACTER_GROUP (
  chargroup_ID int NOT NULL,
  group_participant_ID int NOT NULL REFERENCES MY_CHARACTER(character_ID)
);

CREATE TABLE CAVE (
  game_room_ID int NOT NULL,
  cave_name varchar(255) NOT NULL,
  dm_ID int REFERENCES MY_USER(user_ID),
  dungeon_sub int REFERENCES DUNGEON(dungeon_ID),
  adventure_sub int REFERENCES ADVENTURE(adventure_ID),
  cave_creation_date date DEFAULT current_date NOT NULL,
  playing_group int REFERENCES CHARACTER_GROUP(chargroup_ID),
  PRIMARY KEY(game_room_ID)
);

CREATE TABLE AUTHOR (
  author_ID int NOT NULL,
  email varchar (255) UNIQUE,
  nick varchar (255) UNIQUE
);

CREATE TABLE BASIC_USER(
  basic_ID int PRIMARY KEY REFERENCES MY_USER(user_ID)
);

CREATE TABLE ADMIN_USER(
  admin_ID int PRIMARY KEY REFERENCES MY_USER(user_ID),
  permissions int NOT NULL,
  specialization varchar(255)
);

错误:

  

表BASIC_USER已删除。

     

表ADMIN_USER被删除。

     

表设备掉线了。

     

从第4行开始出错:命令中的4 - DROP TABLE CAVE错误报告 -   SQL错误:ORA-00942:表或视图不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *操作:

     

从命令行的第5行开始出错 - DROP TABLE DUNGEON错误   report - SQL错误:ORA-00942:表或视图不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *操作:

     

从命令行中的第6行开始出错 - DROP TABLE ADVENTURE错误   report - SQL错误:ORA-00942:表或视图不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *行动:表AUTHOR掉线。

     

表CHARACTER_GROUP已删除。

     

表MY_CHARACTER掉线。

     

表MY_USER掉线了。

     

表MY_USER已创建。

     

表MY_CHARACTER已创建。

     

表设备已创建。

     

从第50行开始出错:命令中的50 - CREATE TABLE DUNGEON(
  dungeon_ID int NOT NULL,dungeon_location varchar(255),
  dungeon_difficulty int NOT NULL,目标varchar(2500),状态int   NOT NULL,dungeon_creator_ID int REFERENCES AUTHOR(author_ID),
  检查(dungeon_difficulty&lt; = 5 AND dungeon_difficulty&gt; = 0),PRIMARY   KEY(dungeon_ID))错误报告 - SQL错误:ORA-00942:表或视图   不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *操作:

     

从第6行开始出错:命令中的61 - CREATE TABLE ADVENTURE(
  adventure_ID int NOT NULL,adventure_name varchar(255)NOT NULL,
  adventure_location varchar(255)NOT NULL,adventure_difficulty int   NOT NULL,participant_ID int REFERENCES   CHARACTER_GROUP(chargroup_ID),adventure_goal varchar(2500),
  creator_ID int REFERENCES AUTHOR(author_ID),PRIMARY KEY   (adventure_ID))错误报告 - SQL错误:ORA-00942:表或视图   不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *操作:创建表CHARACTER_GROUP。

     

在命令行中从第7行开始出错 - CREATE TABLE CAVE(
  game_room_ID int NOT NULL,cave_name varchar(255)NOT NULL,dm_ID   int REFERENCES MY_USER(user_ID),dungeon_sub int REFERENCES   DUNGEON(dungeon_ID),adventure_sub int REFERENCES   冒险(adventure_ID),cave_creation_date日期默认   current_date NOT NULL,playing_group int REFERENCES   CHARACTER_GROUP(chargroup_ID),PRIMARY KEY(game_room_ID))错误   report - SQL错误:ORA-00942:表或视图不存在   00942. 00000 - &#34;表或视图不存在&#34;   *原因:
  *行动:表AUTHOR创建。

     

表BASIC_USER已创建。

     

表ADMIN_USER已创建。

知道这个&#34;表格或视图的原因是什么不存在&#34;错误?

1 个答案:

答案 0 :(得分:1)

如果不先定义引用的表,则无法定义外键。因此,您需要做的就是重新排序DDL,以便在引用之前定义所有表。 SQL不直接允许前向引用。

可能存在您可能必须定义循环依赖关系的情况。因此,最好先定义所有表,然后定义应用约束。

DateTimeOffset.Date page on MSDN建议的另一种替代方法是使用CREATE SCHEMA语句,该语句允许创建多个表和视图,并在单个事务中在您自己的模式中执行多个授权,并使用前向引用。

DROP TABLE BASIC_USER;
DROP TABLE ADMIN_USER;
DROP TABLE EQUIPMENT;
DROP TABLE CAVE;
DROP TABLE DUNGEON;
DROP TABLE ADVENTURE;
DROP TABLE AUTHOR;
DROP TABLE CHARACTER_GROUP;
DROP TABLE MY_CHARACTER;
DROP TABLE MY_USER;



CREATE TABLE AUTHOR (
  author_ID int NOT NULL,
  email varchar (255) UNIQUE,
  nick varchar (255) UNIQUE
);

CREATE TABLE MY_USER (
  user_ID int NOT NULL,
  nick varchar(255) NOT NULL,
  date_of_registration date DEFAULT current_date,
  first_name varchar(255) NOT NULL,
  last_name varchar(255),
  email varchar(255) UNIQUE, 
  age int NOT NULL,
  user_location varchar(255),
  finished_adventures int DEFAULT 0 NOT NULL,
  PRIMARY KEY(user_ID)
);



CREATE TABLE BASIC_USER(
  basic_ID int PRIMARY KEY REFERENCES MY_USER(user_ID)
);

CREATE TABLE ADMIN_USER(
  admin_ID int PRIMARY KEY REFERENCES MY_USER(user_ID),
  permissions int NOT NULL,
  specialization varchar(255)
);

CREATE TABLE MY_CHARACTER (
  character_ID int NOT NULL,
  owner_ID int REFERENCES MY_USER(user_ID),
  char_name varchar(255) NOT NULL,
  race varchar(255) NOT NULL,
  char_class varchar(255) NOT NULL,
  char_rank int NOT NULL,
  hp int NOT NULL,
  status int NOT NULL,
  CHECK (char_rank <= 99 AND char_rank >= 0),
  CHECK (hp <= 100 AND hp >= 0),
  CHECK (status <= 1 AND status >= 0),
  PRIMARY KEY(character_ID)
);

CREATE TABLE EQUIPMENT (
  equipment_ID int NOT NULL,
  owner_ID int REFERENCES MY_CHARACTER(character_ID),
  equipment_name varchar(255) NOT NULL,
  equipment_type varchar(255) NOT NULL,
  attack int NOT NULL,
  defense int NOT NULL,
  PRIMARY KEY(equipment_ID)
);

CREATE TABLE DUNGEON (
  dungeon_ID int NOT NULL,
  dungeon_location varchar(255),
  dungeon_difficulty int NOT NULL,
  goal varchar(2500),
  status int NOT NULL,
  dungeon_creator_ID int REFERENCES AUTHOR(author_ID),
  CHECK (dungeon_difficulty <= 5 AND dungeon_difficulty >= 0),
  PRIMARY KEY(dungeon_ID)
);

CREATE TABLE CHARACTER_GROUP (
  chargroup_ID int NOT NULL,
  group_participant_ID int NOT NULL REFERENCES MY_CHARACTER(character_ID)
);

CREATE TABLE ADVENTURE (
  adventure_ID int NOT NULL,
  adventure_name varchar(255) NOT NULL,
  adventure_location varchar(255) NOT NULL,
  adventure_difficulty int NOT NULL,
  participant_ID int REFERENCES CHARACTER_GROUP(chargroup_ID),
  adventure_goal varchar(2500),
  creator_ID int REFERENCES AUTHOR(author_ID),
  PRIMARY KEY (adventure_ID)
);

CREATE TABLE CAVE (
  game_room_ID int NOT NULL,
  cave_name varchar(255) NOT NULL,
  dm_ID int REFERENCES MY_USER(user_ID),
  dungeon_sub int REFERENCES DUNGEON(dungeon_ID),
  adventure_sub int REFERENCES ADVENTURE(adventure_ID),
  cave_creation_date date DEFAULT current_date NOT NULL,
  playing_group int REFERENCES CHARACTER_GROUP(chargroup_ID),
  PRIMARY KEY(game_room_ID)
);