Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Missing right parenthesis

I am trying to execute this script in Oracle 11g and getting the following error, I dont know where I am missing the paranthesis or what is the mistake kindly help me figure this out.

Script:

CREATE TABLE User_Role ( 
  user_role_id INT  NOT NULL  , 
  Users_user_id INT  FOREIGN KEY REFERENCES Users(user_id), 
  User_Types_user_type VARCHAR(20) FOREIGN KEY REFERENCES User_Types(user_type),  
  PRIMARY KEY(user_role_id) 
)

Error:

ORA-00907: missing right parenthesi

like image 687
mdanishs Avatar asked Nov 12 '12 19:11

mdanishs


People also ask

How do I fix missing right parenthesis in SQL?

To correct this error, you must find the part of code that contains the missing right parenthesis, insert the missing symbol in the correct spot, and run the statement again.

Why are there missing right parentheses in SQL?

Cause: A left parenthesis has been entered without a closing right parenthesis, or extra information was contained in the parentheses. All parentheses must be entered in pairs. Action: Correct the syntax and retry the statement.

How do I find missing parentheses in SQL?

If you're using an IDE such as SQL Developer, you can put your cursor next to each parenthesis to see where the matching parenthesis is. If it's in the right spot, great. If the match is showing up somewhere unexpected, then you're missing a parenthesis.

What is missing left parenthesis in SQL?

ORA-00906: missing left parenthesis Cause: A required left parenthesis has been omitted. Certain commands, such as CREATE TABLE, CREATE CLUSTER, and INSERT, require a list of items enclosed in parentheses. Parentheses also are required around subqueries in WHERE clauses and in UPDATE table SET column = (SELECT...)


1 Answers

Delete FOREIGN KEY clause. Rewrite your CREATE TABLE statement as follows:

CREATE TABLE User_Role ( 
      user_role_id         INT  NOT NULL  , 
      Users_user_id        INT  REFERENCES Users(user_id), 
      User_Types_user_type VARCHAR(20) REFERENCES User_Types(user_type),  
      PRIMARY KEY(user_role_id) 
    )

In this case constraint names will be generated by Oracle. If you want to give them more meaningful names you could write your create table statement as follows:

  CREATE TABLE User_Role1 ( 
      user_role_id         INT  NOT NULL  , 
      Users_user_id        INT  , 
      User_Types_user_type VARCHAR(20) ,  
      constraint PK_YourTable PRIMARY KEY(user_role_id), 
      constraint FK_Table_1 foreign key(Users_user_id) REFERENCES Users(user_id),
      constraint FK_Table_2 foreign key(User_Types_user_type) REFERENCES User_Types(user_type)
    )
like image 187
Nick Krasnov Avatar answered Oct 16 '22 10:10

Nick Krasnov