添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Stack Exchange Network

Stack Exchange network consists of 181 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams Registration VARCHAR2(7) PRIMARY KEY, FOREIGN KEY (Vehicle_type_id) REFERENCES Vehicle_type(Vehicle_type_id), GVW INT, Year INT, Body VARCHAR2(15)

Which creates the Vehicle_type table just fine, but when it gets to the foreign key in the Vehicle table I get the error ORA-00904: "VEHICLE_TYPE_ID": invalid identifier .

It's like the Vehicle_type_id column doesn't exist, but it definitely does because it shows up in SQLDeveloper.

Your syntax is off. You need to actually define the column that has the constraint on it, and add the constraint at the end.

CREATE TABLE Vehicle
  Registration VARCHAR2(7) PRIMARY KEY,
  Vehicle_type_id INT,                      -- add this
  GVW INT,
  Year INT,
  Body VARCHAR2(15),
  CONSTRAINT vehicle_type_fk                -- constraint name
    FOREIGN KEY (Vehicle_type_id)           -- constrained column
    REFERENCES Vehicle_type(Vehicle_type_id)

Also you'll need to drop the vehicle table before the vehicle_type table, otherwise you'll get a dependency error:

ORA-02449: unique/primary keys in table referenced by foreign keys
        

Thanks for contributing an answer to Database Administrators Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.