Oracle SQL错误无效的标识符

时间:2016-02-01 23:41:51

标签: sql oracle database-design

编辑:我想出了空问题。现在我对无效标​​识符感到困惑。

我的任务是将ER图转换为在SQL中创建的表。

我在下面发布了我的代码,但是我遇到了很多不同的错误。它们大多是重新出现的错误,但有2-3种不同的错误,

有人可以帮我解决这个问题吗?

COMMIT;

CREATE TABLE Team (
  Team_ID INTEGER GENERATED ALWAYS AS IDENTITY,
  Team_Name NVARCHAR2(40) NOT NULL,
  Team_Manager VARCHAR2(20),
  CONSTRAINT kkeyconst PRIMARY KEY(Team_ID)
);

COMMIT;

  insert into Team(TEAM_NAME, TEAM_MANAGER) VALUES ('Red Sox', 'Jon');
  insert into Team(TEAM_NAME, TEAM_MANAGER) VALUES('White Sox', 'Tony');


CREATE TABLE Driver (
  Driver_id INTEGER,
  Team_ID INTEGER NOT NULL,
  Driver_age INTEGER NOT NULL,
  Driver_Name VARCHAR(20) NOT NULL,
  CONSTRAINT DriverAge CHECK (Driver_age BETWEEN '19' AND '65'),
  CONSTRAINT driverpk PRIMARY KEY(Driver_ID),
  CONSTRAINT Team_FK FOREIGN KEY (Team_ID) REFERENCES Team(Team_ID)
);

 COMMIT;

  INSERT INTO Driver(DRIVER_AGE,DRIVER_NAME) VALUES ('21','jon');
  INSERT INTO Driver(DRIVER_AGE,DRIVER_NAME) VALUES ('43','Tony');

  SELECT * FROM DRIVER;

CREATE TABLE Participation (
   Team_ID INTEGER,
  Driver_ID INTEGER NOT NULL,
  Points INTEGER,
  CONSTRAINT Team_FK FOREIGN KEY (Team_ID) REFERENCES Team(Team_ID),
  CONSTRAINT Driver_FK FOREIGN KEY(Driver_ID) REFERENCES Driver(Driver_ID)
);

COMMIT;
  insert into Participation(Participation_Points) VALUES (150);
  INSERT INTO Participation(Participation_Points) VALUES(300);

  SELECT * FROM PARTICIPATION;


CREATE TABLE Finish (
  Driver_ID INTEGER,
  Finish_Position INTEGER NOT NULL,
  Finish_Result VARCHAR2(50)  NOT NULL,
  CONSTRAINT Driver_FK FOREIGN KEY (Driver_ID) REFERENCES Driver(Driver_id)
);

COMMIT;
  INSERT INTO Finish(Driver_ID, Finish_POSITION, Finish_Result) VALUES ('3','1','Winner');
  INSERT INTO Finish(Driver_ID, Finish_POSITION, Finish_Result) VALUES ('4','3','ThirdPlace');

  SELECT * FROM FINISH;

CREATE TABLE RaceComponent (
  RC_ID INTEGER,
  Driver_ID INTEGER,
  RC_Type VARCHAR(25),
  CONSTRAINT Rcpk  PRIMARY KEY(RC_ID),
  CONSTRAINT Driver_FK FOREIGN KEY (Driver_ID) REFERENCES Driver(Driver_ID)
);

COMMIT;
  INSERT INTO RaceComponent(RC_ID,RC_TYPE) VALUES ('47','Hot Wheels');
  INSERT INTO RaceComponent(RC_ID,RC_TYPE) VALUES ('3', 'Tonka');

  SELECT * FROM RACECOMPONENT;


CREATE TABLE Race (
  Race_Id INTEGER NOT NULL,
  RC_ID INTEGER NOT NULL,
  Race_Title VARCHAR(30) NOT NULL,
  Race_Location VARCHAR(50) NOT NULL,
  Race_Date DATE,
  CONSTRAINT RACE_PK PRIMARY KEY(RACE_ID),
  CONSTRAINT RC_FK FOREIGN KEY (RC_ID) REFERENCES RaceComponent(RC_ID)
 );

 COMMIT;

 INSERT INTO Race(RACE_TITLE, RACE_LOCATION, RACE_DATE) VALUES ('Tonys       Race','Moncton', DATE '2016-04-25');
 INSERT INTO Race(Race_Title, Race_Location, Race_Date) VALUES ('Mikes Racing','San-Francisco', DATE '2015-04-25');

 SELECT * FROM RACE;

ERROR:

Error starting at line : 29 in command -
INSERT INTO Driver(DRIVER_AGE,DRIVER_NAME) VALUES ('21','jon')
Error report -
SQL Error: ORA-01400: cannot insert NULL into   ("STUDENT"."DRIVER"."DRIVER_ID")
01400. 00000 -  "cannot insert NULL into (%s)"
*Cause:    An attempt was made to insert NULL into previously listed objects.
*Action:   These objects cannot accept NULL values.

Error starting at line : 30 in command -
INSERT INTO Driver(DRIVER_AGE,DRIVER_NAME) VALUES ('43','Tony')
Error report -
SQL Error: ORA-01400: cannot insert NULL into   ("STUDENT"."DRIVER"."DRIVER_ID")
01400. 00000 -  "cannot insert NULL into (%s)"
*Cause:    An attempt was made to insert NULL into previously listed objects.
*Action:   These objects cannot accept NULL values.

 DRIVER_ID   TEAMS_ID DRIVER_AGE DRIVER_NAME        
---------- ---------- ---------- --------------------
     1                    21 jon                 
     2                    43 Tony                


Error starting at line : 34 in command -
CREATE TABLE Participation (
  Team_ID INTEGER,
  Driver_ID INTEGER NOT NULL,
  Points INTEGER,
  CONSTRAINT Team_FK FOREIGN KEY (Team_ID) REFERENCES Team(Team_ID),
   CONSTRAINT Driver_FK FOREIGN KEY(Driver_ID) REFERENCES Driver(Driver_ID)
)
Error report -
SQL Error: ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Commit complete.


Error starting at line : 43 in command -
insert into Participation(Participation_Points) VALUES (150)
Error at Command Line : 43 Column : 27
Error report -
SQL Error: ORA-00904: "PARTICIPATION_POINTS": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 44 in command -
INSERT INTO Participation(Participation_Points) VALUES(300)
Error at Command Line : 44 Column : 27
Error report -
SQL Error: ORA-00904: "PARTICIPATION_POINTS": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

                        TEAMNAME_ID  DRIVER_ID
--------------------------------------- ----------
                       POINTSEARNED
---------------------------------------

                                150


                                150


                                150

Commit complete.


Error starting at line : 57 in command -
INSERT INTO Finish(Driver_ID, Finish_POSITION, Finish_Result) VALUES    ('3','1','Winner')
Error at Command Line : 57 Column : 48
Error report -
SQL Error: ORA-00904: "FINISH_RESULT": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 58 in command -
INSERT INTO Finish(Driver_ID, Finish_POSITION, Finish_Result) VALUES    ('4','3','ThirdPlace')
Error at Command Line : 58 Column : 48
Error report -
SQL Error: ORA-00904: "FINISH_RESULT": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

no rows selected

Commit complete.


  Error starting at line : 71 in command -
  INSERT INTO RaceComponent(RC_ID,RC_TYPE) VALUES ('47','Hot Wheels')
Error report -
SQL Error: ORA-00001: unique constraint (STUDENT.RCPK) violated
00001. 00000 -  "unique constraint (%s.%s) violated"
*Cause:    An UPDATE or INSERT statement attempted to insert a duplicate   key.
       For Trusted Oracle configured in DBMS MAC mode, you may see
       this message if a duplicate entry exists at a different level.
*Action:   Either remove the unique restriction or do not insert the key.

Error starting at line : 72 in command -
INSERT INTO RaceComponent(RC_ID,RC_TYPE) VALUES ('3', 'Tonka')
Error report -
SQL Error: ORA-00001: unique constraint (STUDENT.RCPK) violated
00001. 00000 -  "unique constraint (%s.%s) violated"
*Cause:    An UPDATE or INSERT statement attempted to insert a duplicate    key.
       For Trusted Oracle configured in DBMS MAC mode, you may see
       this message if a duplicate entry exists at a different level.
*Action:   Either remove the unique restriction or do not insert the key.

     RC_ID DRIVER1_ID RC_TYPE                 
---------- ---------- -------------------------
    47            Hot Wheels               
     3            Tonka                    


Commit complete.

Error starting at line : 89 in command -
INSERT INTO Race(RACE_TITLE, RACE_LOCATION, RACE_DATE) VALUES ('Tonys    Race','Moncton', DATE '2016-04-25')
Error report -
SQL Error: ORA-01400: cannot insert NULL into ("STUDENT"."RACE"."RACE_ID")
01400. 00000 -  "cannot insert NULL into (%s)"
*Cause:    An attempt was made to insert NULL into previously listed objects.
*Action:   These objects cannot accept NULL values.

Error starting at line : 90 in command -
INSERT INTO Race(Race_Title, Race_Location, Race_Date) VALUES ('Mikes    Racing','San-Francisco', DATE '2015-04-25')
Error report -
SQL Error: ORA-01400: cannot insert NULL into ("STUDENT"."RACE"."RACE_ID")
01400. 00000 -  "cannot insert NULL into (%s)"
*Cause:    An attempt was made to insert NULL into previously listed objects.
*Action:   These objects cannot accept NULL values.

   RACE_ID      RC_ID RACE_TITLE
---------- ---------- ------------------------------
RACE_LOCATION                                      RACE_DATE
-------------------------------------------------- ---------
     1            Tonys Race                     
Moncton                                            25-APR-16

    43            MikesRacing                    
San-Francisco                                      25-APR-15

0 个答案:

没有答案