2017-12-26 17 views
-2
existiert

Das Problem Ich habe istORA-00907: fehlende rechte Klammer und ORA-00942: Tabelle oder Sicht nicht

  • ORA-00907: rechte Klammer und
  • ORA-00942 fehlt: Tabelle oder Ansicht existiert nicht.

Screenshot des Fehlers ist enter image description hereenter image description here

DROP TABLE Organizer CASCADE CONSTRAINT; 
DROP TABLE festival CASCADE CONSTRAINT; 
DROP TABLE staff CASCADE CONSTRAINT; 
DROP TABLE act CASCADE CONSTRAINT; 
DROP TABLE equipment CASCADE CONSTRAINT; 
DROP TABLE stage CASCADE CONSTRAINT; 
DROP TABLE band CASCADE CONSTRAINT; 
DROP TABLE agent CASCADE CONSTRAINT; 
DROP TABLE venue CASCADE CONSTRAINT; 
DROP TABLE band_agent CASCADE CONSTRAINT; 

Tabellenerstellung

  • Jede Einheit auf dem Modell wird durch eine Tabelle dargestellt, die in der Datenbank erstellt werden muss.
  • In SQL werden neue Tabellen mit dem Befehl CREATE TABLE erstellt.
  • Wenn eine Tabelle erstellt wird, werden ihr Name und ihre Attribute definiert.
  • Die Werte davon sind von denen im Modell angegeben abgeleitet.
  • Bestimmte Einschränkungen werden manchmal auch angegeben, z. B. die Identifizierung von Primärschlüsseln.
-- Create a Database table to represent the "Organizer" entity. 
    CREATE TABLE Organizer(
     OrganizerId INTEGER NOT NULL, 
     oranizerName VARCHAR(55) NOT NULL, 
     organizerAddress VARCHAR(55), 
     organizerPhone INTEGER, 
     -- Specify the PRIMARY KEY constraint for table "Organizer". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_Organizer PRIMARY KEY (OrganizerId) 
    ); 

    -- Create a Database table to represent the "festival" entity. 
    CREATE TABLE festival(
     festvalId INTEGER NOT NULL, 
     festivalName VARCHAR(55) NOT NULL, 
     festvalLocation VARCHAR(55) NOT NULL, 
     festivalPeriod INTEGER, 
     fk1_OrganizerId NUMBER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "festival". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_festival PRIMARY KEY (festvalId) 
    ); 

    -- Create a Database table to represent the "staff" entity. 
    CREATE TABLE staff(
     staffId INTEGER NOT NULL, 
     fk1_venueId INTEGER NOT NULL, 
     fk2_staffId INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "staff". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_staff PRIMARY KEY (staffId) 
    ); 

    -- Create a Database table to represent the "equipment" entity. 
    CREATE TABLE equipment(
     equipmentmodel INTEGER NOT NULL, 
     equipmentname VARCHAR(55), 
     equipmenttype VARCHAR(55), 
     fk1_stageId INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "equipment". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_equipment PRIMARY KEY (equipmentmodel)); 

    -- Create a Database table to represent the "act" entity. 
    CREATE TABLE act(
     actId INTEGER NOT NULL, 
     typeOfAct VARCHAR(55) NOT NULL, 
     actName VARCHAR(55), 
     fk1_bandId INTEGER NOT NULL, 
     fk2_festvalId INTEGER NOT NULL, 
     fk3_stageId INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "act". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_act PRIMARY KEY (actId) 
    ); 

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

    -- Create a Database table to represent the "band" entity. 
    CREATE TABLE band(
     bandId INTEGER NOT NULL, 
     bandName VARCHAR(55), 
     bandAddress VARCHAR(55), 
     bandPhone INTEGER, 
     -- Specify the PRIMARY KEY constraint for table "band". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_band PRIMARY KEY (bandId) 
    ); 

    -- Create a Database table to represent the "agent" entity. 
    CREATE TABLE agent(
     agentId INTEGER NOT NULL, 
     agentName VARCHAR(55), 
     agentAddress VARCHAR(55), 
     agentPhone INTEGER, 
     -- Specify the PRIMARY KEY constraint for table "agent". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_agent PRIMARY KEY (agentId) 
    ); 

    -- Create a Database table to represent the "venue" entity. 
    CREATE TABLE venue(
     venueId INTEGER NOT NULL, 
     venueName VARCHAR(55) NOT NULL, 
     venueLocation VARCHAR(55), 
     venueType VARCHAR(55), 
     fk1_festvalId INTEGER NOT NULL, 
     -- Specify the PRIMARY KEY constraint for table "venue". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_venue PRIMARY KEY (venueId) 
    ); 

    -- Create a Database table to represent the "band_agent" entity. 
    CREATE TABLE band_agent(
     fk1_bandId INTEGER NOT NULL, 
     fk2_agentId INTEGER NOT NULL 
    ); 

    -- Create a Database table to represent the "first aider" entity. 
    -- This table is representing a sub-type entity, so the primary key will be the same as that 
    -- defined for table "staff" which represents the super-type entity. 
    CREATE TABLE first_aider(
     staffId INTEGER NOT NULL, 
     name VARCHAR(25), 
     -- Specify the PRIMARY KEY constraint for table "first_aider". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_first_aider PRIMARY KEY (staffId), 
     -- Specify a FOREIGN KEY constraint to indicate that this table's primary key (staffId) 
     -- references the super-type table's primary key. In this case the key of table "staff" 
     -- The ON DELETE CASCADE and ON UPDATE CASCADE ensure that if the super-type key data is 
     -- deleted or updated then the changes will be cascaded down to this sub-type. 
     -- i.e. if the value of the super-type key is changed the value of this table's key is also changed. 
     FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
    ); 

    -- Create a Database table to represent the "security" entity. 
    -- This table is representing a sub-type entity, so the primary key will be the same as that 
    -- defined for table "staff" which represents the super-type entity. 
    CREATE TABLE security(
     staffId INTEGER NOT NULL, 
     name VARCHAR(55), 
     -- Specify the PRIMARY KEY constraint for table "security". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_security PRIMARY KEY (staffId), 
     -- Specify a FOREIGN KEY constraint to indicate that this table's primary key (staffId) 
     -- references the super-type table's primary key. In this case the key of table "staff" 
     -- The ON DELETE CASCADE and ON UPDATE CASCADE ensure that if the super-type key data is 
     -- deleted or updated then the changes will be cascaded down to this sub-type. 
     -- i.e. if the value of the super-type key is changed the value of this table's key is also changed. 
     FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
    ); 

    -- Create a Database table to represent the "supervisor" entity. 
    -- This table is representing a sub-type entity, so the primary key will be the same as that 
    -- defined for table "staff" which represents the super-type entity. 
    CREATE TABLE supervisor(
     staffId INTEGER NOT NULL, 
     name VARCHAR(8), 
     -- Specify the PRIMARY KEY constraint for table "supervisor". 
     -- This indicates which attribute(s) uniquely identify each row of data. 
     CONSTRAINT pk_supervisor PRIMARY KEY (staffId), 
     -- Specify a FOREIGN KEY constraint to indicate that this table's primary key (staffId) 
     -- references the super-type table's primary key. In this case the key of table "staff" 
     -- The ON DELETE CASCADE and ON UPDATE CASCADE ensure that if the super-type key data is 
     -- deleted or updated then the changes will be cascaded down to this sub-type. 
     -- i.e. if the value of the super-type key is changed the value of this table's key is also changed. 
     FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
    ); 


    -------------------------------------------------------------- 
    -- Alter Tables to add fk constraints -- 

    -- Now all the tables have been created the ALTER TABLE command is used to define some additional 
    -- constraints. These typically constrain values of foreign keys to be associated in some way 
    -- with the primary keys of related tables. Foreign key constraints can actually be specified 
    -- when each table is created, but doing so can lead to dependency problems within the script 
    -- 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 "organizer_to_festival" relationship 

    -- This constraint ensures that the foreign key of table "festival" 
    -- correctly references the primary key of table "Organizer" 

    ALTER TABLE festival ADD CONSTRAINT fk1_festival_to_Organizer FOREIGN KEY(fk1_OrganizerId) REFERENCES Organizer(OrganizerId); 

    -- Alter table to add new constraints required to implement the "stage_to_equipment" relationship 

    -- This constraint ensures that the foreign key of table "equipment" 
    -- correctly references the primary key of table "stage" 

    ALTER TABLE equipment ADD CONSTRAINT fk1_equipment_to_stage FOREIGN KEY(fk1_stageId) REFERENCES stage(stageId); 

    -- Alter table to add new constraints required to implement the "band_to_acts" relationship 

    -- This constraint ensures that the foreign key of table "act" 
    -- correctly references the primary key of table "band" 

    ALTER TABLE act ADD CONSTRAINT fk1_act_to_band FOREIGN KEY(fk1_bandId) REFERENCES band(bandId); 

    -- Alter table to add new constraints required to implement the "festival_to_act" relationship 

    -- This constraint ensures that the foreign key of table "act" 
    -- correctly references the primary key of table "festival" 

    ALTER TABLE act ADD CONSTRAINT fk2_act_to_festival FOREIGN KEY(fk2_festvalId) REFERENCES festival(festvalId); 

    -- Alter table to add new constraints required to implement the "festival_to_venue" relationship 

    -- This constraint ensures that the foreign key of table "venue" 
    -- correctly references the primary key of table "festival" 

    ALTER TABLE venue ADD CONSTRAINT fk1_venue_to_festival FOREIGN KEY(fk1_festvalId) REFERENCES festival(festvalId); 

    -- Alter table to add new constraints required to implement the "band_to_band_agent" relationship 

    -- This constraint ensures that the foreign key of table "band_agent" 
    -- correctly references the primary key of table "band" 

    ALTER TABLE band_agent ADD CONSTRAINT fk1_band_agent_to_band FOREIGN KEY(fk1_bandId) REFERENCES band(bandId); 

    -- Alter table to add new constraints required to implement the "agent_to_band_agent" relationship 

    -- This constraint ensures that the foreign key of table "band_agent" 
    -- correctly references the primary key of table "agent" 

    ALTER TABLE band_agent ADD CONSTRAINT fk2_band_agent_to_agent FOREIGN KEY(fk2_agentId) REFERENCES agent(agentId); 
    -- Alter table to add new constraints required to implement the "supervises" relationship 

    -- This constraint ensures that the foreign key of table "staff" 
    -- correctly references the primary key of table "supervisor" 

    ALTER TABLE staff ADD CONSTRAINT fk2_staff_to_supervisor FOREIGN KEY(fk2_staffId) REFERENCES supervisor(staffId); 
    -- Alter table to add new constraints required to implement the "staff_to_venue" relationship 

    -- This constraint ensures that the foreign key of table "staff" 
    -- correctly references the primary key of table "venue" 

    ALTER TABLE staff ADD CONSTRAINT fk1_staff_to_venue FOREIGN KEY(fk1_venueId) REFERENCES venue(venueId); 

    -- Alter table to add new constraints required to implement the "act_stage" relationship 

    -- This constraint ensures that the foreign key of table "act" 
    -- correctly references the primary key of table "stage" 

    ALTER TABLE act ADD CONSTRAINT fk3_act_to_stage FOREIGN KEY(fk3_stageId) REFERENCES stage(stageId); 



     enter code here 

    -------------------------------------------------------------- 
    -- End of DDL file auto-generation 
    -------------------------------------------------------------- 
+2

Ist 'der Code hier' Linie Teil der Abfrage eingeben Sie führen aus? –

+1

Anstatt einen riesigen Code-Code zu veröffentlichen, sollten Sie nur das Bit posten, das das Problem verursacht.All diese langweiligen Textbaustein-Spalten können es Ihren Mitarbeitern erleichtern, Ihren Code zu verstehen (obwohl ich das bezweifle). Aber es macht es natürlich viel schwieriger für die Verwendung, um Ihr Problem zu finden. Außerdem ist es für Sie eine gute Übung, eine fokussierte Frage mit einem reproduzierbaren Testfall zu formulieren: Es hilft Ihnen, SQL zu lernen, und Sie können Ihr Problem vielleicht lösen, ohne überhaupt eine Frage stellen zu müssen. – APC

+0

Wenn Sie versuchen, ein [minimales, vollständiges und überprüfbares Beispiel] (https://stackoverflow.com/help/mcve) wie empfohlen zu erstellen und keine Bilder zu posten (wie empfohlen), aber ein Skript ausführen und die Ausgabe als veröffentlichen Text das Problem wird von selbst lösen. – miracle173

Antwort

0

Es gibt keine Klausel ON UPDATE CASCADE während ON DELETE CASCADE existieren

diese Klauseln als das Entfernen folgende:

CREATE TABLE first_aider(
    staffId INTEGER NOT NULL, 
    name VARCHAR(25), 
    CONSTRAINT pk_first_aider 
    PRIMARY KEY (staffId), 
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE 
); 

UND

CREATE TABLE security(
    staffId INTEGER NOT NULL, 
    name VARCHAR(55), 
    CONSTRAINT pk_security 
    PRIMARY KEY (staffId), 
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE 
); 

UND

CREATE TABLE supervisor(
    staffId INTEGER NOT NULL, 
    name VARCHAR(8), 
    CONSTRAINT pk_supervisor 
    PRIMARY KEY (staffId),  
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE 
); 
+0

Dieses Format ist unglaublich schlecht. – miracle173

+0

Darüber hinaus gibt es keine Notwendigkeit, den 'PRIMARY KEY (staffId) zu entfernen,' tatsächlich benennt er die Fremdschlüssel "pk_security" und "pk_supervisor", was sicherlich nicht beabsichtigt ist. – miracle173

+0

@wunder173 danke, du hast Recht. Ich habe meine Antwort für den richtigen Stil bearbeitet. –

1

Ein Fremdschlüssel Definition ist hier falsch:

CREATE TABLE first_aider(
    ...... 
    ...... 
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
); 

Oracle nicht ON UPDATE CASCADE Klausel nicht kennt, nach the documentation nur ON DELETE CASCADE oder ON DELETE SET NULL erlaubt sind. Sie müssen ON UPDATE CASCADE entfernen.

enter image description here


Der gleiche Fehler ist hier:

CREATE TABLE security(
    ...... 
    ...... 
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
); 

und auch hier:

CREATE TABLE supervisor(
    ...... 
    ...... 
    FOREIGN KEY(staffId) REFERENCES staff(staffId) ON DELETE CASCADE ON UPDATE CASCADE 
); 
Verwandte Themen