1 Replies - 1050 Views - Last Post: 17 December 2015 - 04:12 PM

#1 kyle01  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 194
  • Joined: 26-November 14

Creating a Table in Oracle

Posted 17 December 2015 - 02:25 PM

I have produced this code for oracle but I have a question, I've tried adding a foreign key from a existing table but it doesn't work, I don't want to try run the code again in case it messes anything up, but my question is; what syntax or code would i add to my Bookings table code below to add a foreign key

CREATE TABLE Bookings
(
Booking_ID_Number VARCHAR2(10) NOT NULL,
Trip_Details VARCHAR2(120) NOT NULL,
Date_Required DATE NOT NULL,
PRIMARY KEY (Booking_ID_Number),
FOREIGN KEY (Customer_ID)
);



CREATE TABLE Customers
(
Customer_ID VARCHAR2(10) NOT NULL,
Contact_Name VARCHAR2(60) NOT NULL,
PRIMARY KEY (Customer_ID)
);




^ Would i add the foreign key like this, or is there a more correct way of going about it, thanks for any answers.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a Table in Oracle

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 6966
  • View blog
  • Posts: 14,572
  • Joined: 16-October 07

Re: Creating a Table in Oracle

Posted 17 December 2015 - 04:12 PM

For a foreign key you also need the foreign entity you're associating it with.

Keys are a form of constraint are can be create with more standard with constraint syntax. Though Oracle offers some helpful shorthand. More here: http://www.orafaq.com/wiki/Foreign_key
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1