Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 ora-00924 error problems

Author  Topic 

hansmoolman
Starting Member

4 Posts

Posted - 2010-11-29 : 11:11:09
Can anyone please help. I am doing a project for college and Im currently stuck on an issue. I can create tables etc. with their primary keys, but as soon as I add a foreign key and try to insert some values into A table, I get the ora-00924 error "table or view does not exist". I have double checked my spelling etc. but still no luck. Can anyone see where I am going wrong please. I need this issue resolved before I can continue with the next phase of the project and my time is running out fast. Here is a small sample of my database so far.

I get the error messages when I create the views as well as when I add my foreign keys.


DROP TABLE PATIENT;
DROP TABLE PLAYER;
DROP TABLE WARD CASCADE CONSTRAINTS;



--CREATE TABLES
CREATE TABLE WARD(
WARDNO INTEGER NOT NULL,
WARDNAME VARCHAR2(20) NOT NULL,
PATIENTID VARCHAR2(20) NOT NULL,
PLAYERID VARCHAR2(20) NOT NULL,
NPCNAME VARCHAR2(20) NOT NULL,
NUMPATIENTSINWARD INTEGER NOT NULL CONSTRAINT NUMPATIENTSINWARD_CHECK CHECK(NUMPATIENTSINWARD >= 0 AND NUMPATIENTSINWARD <= 10),
CONSTRAINT WARD_PK PRIMARY KEY(WARDNO));

CREATE TABLE PLAYER(
PLAYERID VARCHAR2(20) NOT NULL,
PLAYERLEVEL INTEGER NOT NULL CONSTRAINT PLAYERLEVEL_CHECK CHECK(PLAYERLEVEL >= 0 AND PLAYERLEVEL <= 99), USERNAME VARCHAR2(20) NOT NULL,
PASSWORD VARCHAR2(20) NOT NULL,
POINTS INTEGER NOT NULL,
PLAYER_WARDNO INTEGER NOT NULL,
PLAYER_PATIENTID VARCHAR2(20) NOT NULL,
CONSTRAINT PLAYER_PK PRIMARY KEY(PLAYERID),
CONSTRAINT PLAYER_WARDNO_FK FOREIGN KEY(PLAYER_WARDNO) REFERENCES WARD(WARDNO),
CONSTRAINT PLAYER_PATIENTID_FK FOREIGN KEY(PLAYER_PATIENTID) REFERENCES PATIENT(PATIENTID));


CREATE TABLE PATIENT(
PATIENTID VARCHAR2(20) NOT NULL,
PATIENTNAME VARCHAR2(20) NOT NULL,
PATIENTSTATE VARCHAR2(20) NOT NULL,
PATIENTDESCRIPTOR CHAR NOT NULL,
PATIENT_PLAYERID VARCHAR2(20) NOT NULL,
PATIENT_WARDNO INTEGER NOT NULL,
CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENTID),
CONSTRAINT PATIENT_PLAYERID_FK FOREIGN KEY(PATIENT_PLAYERID) REFERENCES PLAYER(PLAYERID),
CONSTRAINT PATIENT_WARDNO_FK FOREIGN KEY(PATIENT_WARDNO) REFERENCES WARD(WARDNO));

INSERT INTO WARD VALUES(1, 'WARD A', 'PATIENTID HANS', 'PLAYERID DAN', 'NPCNAME HUGO', NUMPATIENTSINWARD_CQENCE.NEXTVAL);
INSERT INTO PLAYER VALUES ('PLAYERID DAN', 1, 'USERNAME GRAHAM', 'PASSWORD GRAHAM', 1, 1, 'PATIENTID HANS');
INSERT INTO PATIENT VALUES('PATIENTID HANS', 'PATIENTNAME JAMES', 'SICK', 'R', 'PLAYERID DAN', 1);




CREATE VIEW VIEW_PLAYER
AS SELECT PLAYERID, PLAYERLEVEL, POINTS, WARDNO
FROM PLAYER;

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-29 : 11:21:42
Oracle?

Are you running this as a single script?
Maybe you need to create the tables first then add the FKs then run the inserts.
Your second table has an FK to the third table - it will fail because the third table doesn't exist.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

hansmoolman
Starting Member

4 Posts

Posted - 2010-11-29 : 12:35:34
Yeah Im running this as a single script from SQL Plus. "Maybe you need to create the tables first then add the FKs then run the inserts." - how would I do this? If I first create all the tables without the foreign keys and then run it, how would I add the foreign keys after and then insert? Sorry if this seems a very basic question but I am just starting off with databases and there is still a lot for me to learn. I eventually just created all the tables without foreign keys and there was no problem inserting data into them, but as soon as I added the foreign keys, everything started going wrong. Also, "Your second table has an FK to the third table - it will fail because the third table doesn't exist." - how would I get around this problem. If I create the Patient before the Player, then Ill just have the same error but the other way around for the tables as the reference(? dont know if this is the right term to use) each other? Or might there be something wrong with the way I have my database desighned I wonder?


Go to Top of Page

hansmoolman
Starting Member

4 Posts

Posted - 2010-11-29 : 12:37:14
quote:
Originally posted by nigelrivett

Oracle?

Are you running this as a single script?
Maybe you need to create the tables first then add the FKs then run the inserts.
Your second table has an FK to the third table - it will fail because the third table doesn't exist.



Yeah Im running this as a single script from SQL Plus. "Maybe you need to create the tables first then add the FKs then run the inserts." - how would I do this? If I first create all the tables without the foreign keys and then run it, how would I add the foreign keys after and then insert? Sorry if this seems a very basic question but I am just starting off with databases and there is still a lot for me to learn. I eventually just created all the tables without foreign keys and there was no problem inserting data into them, but as soon as I added the foreign keys, everything started going wrong. Also, "Your second table has an FK to the third table - it will fail because the third table doesn't exist." - how would I get around this problem. If I create the Patient before the Player, then Ill just have the same error but the other way around for the tables as the reference(? dont know if this is the right term to use) each other? Or might there be something wrong with the way I have my database desighned I wonder?
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-29 : 12:44:21
Yep - wouldn't normally have an FK going both ways between two tables. It would mean that you can't create the tables then populate as the insert into the first table would violate the FK to the other.
I suspect you need to take the patientid - playerid columns off the tables and create a new conjoint table player_patient with the two id's.
If you are trying to model a many to many join that's the way it would be done.

You say you're doing a project for college. Does it include anything about relational theory or relational database design?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

hansmoolman
Starting Member

4 Posts

Posted - 2010-11-29 : 13:12:53
quote:
Originally posted by nigelrivett

You say you're doing a project for college. Does it include anything about relational theory or relational database design?



Yeah it does but its the next topic to be covered. If you ask me its being taught the wrong way around....but who am I to say. So I should take both the PlayerID and PatientID out of Player and Patient and put them in a seperate table? Ill maybe read ahead in our notes and see if I can come up with the solution.
Go to Top of Page
   

- Advertisement -