1

I'm trying to write a script in Apex to create multiple tables. The first table is created with no issues but every table after that one gives me a missing parenthesis issue. Sometimes it's the left, sometimes it's the right. I've tried everything with no avail.

I have debugged it numerous times, spoken with the others and have not found the solution.

Create Table Employee -- Creates Employee table and references it to ProjDept table ( EmployeeID Number(4) Not Null, FirstName VarChar2(15) Not Null, LastName VarChar2(20) Not Null, ProjDeptID Number(4) Not Null, PhoneNumber Number(10), Constraint Employee_pk Primary Key (EmployeeID), -- sets primary key for table Constraint Employee_FK Foreign Key References ProjDept(ProjDeptID)-- identifies foreign key ); 

This is the second table in the script that won't work, the next 2 tables generate similar errors.

2 Answers 2

4

You forgot to include the name of the column which is referencing another in the foreign key:

Create Table Employee ( EmployeeID Number(4) Not Null, FirstName VarChar2(15) Not Null, LastName VarChar2(20) Not Null, ProjDeptID Number(4) Not Null, PhoneNumber Number(10), Constraint Employee_pk Primary Key (EmployeeID), -- sets primary key for table Constraint Employee_FK Foreign Key (ProjDeptId) References ProjDept(ProjDeptID)-- identifies foreign key ); 

db<>fiddle

Sign up to request clarification or add additional context in comments.

3 Comments

I don't understand what you mean. I put that it referenced the ProjDept table and then the ProjDeptID column.
@Kampe24 Compare your code Foreign Key References to my code Foreign Key (ProjDeptId) References. You stated that there is a foreign key and that it references to the PrejDeptID column of the ProjDept table but you did not state which column of the Employee table it is referencing from; that column name(s) need to be stated between the FOREIGN KEY and REFERENCES keywords.
Wow I can't believe I missed that. Thanks for helping me out I was going crazy over that.
0

Where exactly in Apex are you executing those commands?

If SQL Workshop's SQL Commands, then you can't have more than a single command in there, i.e. you should create tables one by one:

  • create the first table
  • delete that create table command and write another one, for the second table; then create it
  • the same goes for other tables as well

Alternatively, go to SQL Workshop's SQL Scripts and put all your commands into a script, e.g.

create table a (id number, name varchar2(20), ...); create table b (cdate date, ...); 

save & run the script.

2 Comments

I'm writing them in the SQL Scripts section. The above answer worked but now I'm getting a different error. I have a table that has a composite key using 2 other primary keys from other tables and it won't let me do it saying the keys are already assigned to other tables.
Two options: drop "other tables" (if you don't need them), or (safer option) rename those constraints you're trying to create right now. If you want to check where those constraints are already used, query USER_CONSTRAINTS.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.