-1

In sql plus I am creating a table but it is giving:

error 00903:invalid table name ...

I gave names "convict". Then "guilty_dt". Then "pranshu"... all three cases are giving error.

create table"convict"(
    "convict_no"varchar2(10),
    "name"varchar2(20),
    "address"varchar2(20),
    "location"varchar2(20),
    "degree"varchar2(10),
    constraint pk primary key("convict_no"),
    constraint fkadd foreign key("address")references("prison"),
    constraint fkloc foreign key("location")references("clocation"),
    constraint chk check("degree"('0d','1d','2d','3d')));
APC
  • 144,005
  • 19
  • 170
  • 281
pran
  • 9
  • Why did you use the double quotes in table name and fields name. – S_sauden Jun 27 '17 at 04:55
  • 3
    Especially, why insist on *lower-case* names in double-quotes? That practice will cause you so much grief and any other developer who has to work with your data model will hate you. – APC Jun 27 '17 at 05:18
  • Beyond that, your table statement has two foreign keys. Do the referenced tables exist? Do they have primary keys? – APC Jun 27 '17 at 05:19
  • yes i have made referenced tables prior making this table naming "prison"and "clocation" – pran Jun 27 '17 at 08:06
  • I TRIED THIS....... CREATE TABLE CONVICT("convict_no"varchar2(10) NOT NULL,"name"varchar2(20),"address"varchar2(20),"location"varchar2(20),"degree"varchar2(10),CONSTRAINT PK PRIMARY KEY(convict_no),FOREIGN KEY(address)REFERENCES PRISON(address),FOREIGN KEY(location)REFERENCES CLOCATION(location),CONSTRAINT CHK CHECK(degree('0d','01','02','03'))); NOW IT GIVING ERROR--ORA-ORA-00920: invalid relational operator – pran Jun 27 '17 at 08:21

2 Answers2

2

Use this syntax:

CREATE TABLE table_name
(
  column1 datatype null/not null,
  ...
  CONSTRAINT fk_column
    FOREIGN KEY (column1, column2, ... column_n)
    REFERENCES parent_table (column1, column2, ... column_n)
);

REFERENCES parent_table

I3rutt
  • 574
  • 4
  • 18
-1

Try this:-

1. Why did you use the double quotes in table name and fields name.
2. Where is your parent table in foreign key constraint condition.Must be 
   exist parent table in foreign key constraint.
S_sauden
  • 302
  • 2
  • 10
  • 2
    This is not an answer. These should be comments except that I have already made both points. By all means upvote my comments. – APC Jun 27 '17 at 06:40