Create Table Error - Oracle SQL

萝らか妹 提交于 2021-02-17 06:19:04

问题


I need help with this it keeps giving the same error in Oracle SQL Developer.

Error starting at line : 15 in command -

CREATE TABLE B_BOOKING (
    booking_number int NOT NULL PRIMARY KEY,
    date_booked date,
    performance_order int,
    base_pay int,
    band_number int,
    concert_number int, FOREIGN KEY REFERENCES B_CONCERT(concert_number)
)

Error at Command Line : 21 Column : 34 Error report - SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis" *Cause:
*Action:


回答1:


You appear to be trying to declare a foreign key inline and have the syntax incorrect, you want:

CREATE TABLE B_BOOKING (
    booking_number int PRIMARY KEY,
    date_booked date,
    performance_order int,
    base_pay int,
    band_number int,
    concert_number int REFERENCES B_CONCERT(concert_number)
)

Also, you do not need a NOT NULL constraint on a PRIMARY KEY column.

Alternatively you can declare the constraint as:

CREATE TABLE B_BOOKING (
    booking_number int PRIMARY KEY,
    date_booked date,
    performance_order int,
    base_pay int,
    band_number int,
    concert_number int,
    CONSTRAINT constraint_name FOREIGN KEY ( concert_number )
                               REFERENCES B_CONCERT(concert_number)
)


来源:https://stackoverflow.com/questions/46857105/create-table-error-oracle-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!