SQL - 缺少右括号 [英] SQL - Missing right parenthesis

查看:45
本文介绍了SQL - 缺少右括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Oracle 11g 中执行此脚本并收到以下错误,我不知道我在哪里缺少括号或错误是什么,请帮助我解决这个问题.

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.

脚本:

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) 
)

错误:

ORA-00907:缺少右括号

ORA-00907: missing right parenthesi

推荐答案

删除 FOREIGN KEY 子句.如下重写您的 CREATE TABLE 语句:

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) 
    )

在这种情况下,约束名称将由 Oracle 生成.如果你想给他们更有意义的名字,你可以写你的 create table 语句如下:

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)
    )

这篇关于SQL - 缺少右括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆