473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

constraint error when creating table relationships

3
I am not sure exactly what i am doing run but when I run this code in sql plus i get constraint error on most of my tables except author and books table. Please help I am new to Programming in PL/SQL.



--Create All Tables

CREATE TABLE authors (
auth_id NUMBER(7),
f_name VARCHAR2(30),
l_name VARCHAR2(50),
auth_specialty VARCHAR2(30),
CONSTRAINT auth_id_pk PRIMARY KEY(auth_id)
);


CREATE TABLE books (
isbn CHAR (10) PRIMARY KEY,
title VARCHAR2 (50),
qty_owned NUMBER(3),
qty_on_hand NUMBER(3),
cost NUMBER,
location VARCHAR2(35),
auth_FK NUMBER CONSTRAINT books_auth_FK REFERENCES authors(auth_id)
);

CREATE TABLE book_details(
Num_Pages NUMBER(10),
copyright DATE,
publisher VARCHAR2(50),
category VARCHAR2(20),
isbn_nu_FK CHAR CONSTRAINT books_isbn_nu_FK REFERNECES books(isbn)
);

CREATE TABLE customer(
lib_card_id NUMBER(9) PRIMARY KEY, --no duplicates
f_name VARCHAR2(30),
l_name VARCHAR2(50),
num_str VARCHAR2(30),
city VARCHAR2(30),
zip VARCHAR2(7),
phone VARCHAR2(13),
card_start_date DATE,
card_exp_date DATE,
member_since DATE,
rental_id_FK NUMBER CONSTRAINT customer_rental_id_FK REFERENCES rentals(rental_id)
);

CREATE TABLE rental_details(
rental_id_FK NUMBER CONSTRAINT rentals_rental_id_FK REFERENCES rentals(rental_id),
isbn_num_FK NUMBER CONSTRAINT books_isbn_num_FK REFERENCES books(isbn),
quanity NUMBER(5),
rental_date DATE,
due_date DATE,
);

CREATE TABLE rentals(
rental_id NUMBER(7) PRIMARY KEY,
isbn_nu_FK NUMBER CONSTRAINT books_isbn_nu_FK REFERENCES books(isbn),
lib_card_FK NUMBER CONSTRAINT customer_lib_card_FK REFERENCES customer(lib_card_id),
employ_id_FK NUMBER CONSTRAINT employee_employ_id_FK REFERENCES employee(employee_id)
);

CREATE TABLE employee(
employee_id NUMBER(9) PRIMARY KEY,
f_name VARCHAR2(30),
l_name VARCHAR2(50),
num_str VARCHAR2(35),
city VARCHAR2(25),
state VARCHAR2(2),
zip VARCHAR2(5),
SSN VARCHAR2(9),
multi_lingual VARCHAR2(20),
ext VARCHAR2(3),
position VARCHAR2(25),
);
Aug 18 '07 #1
4 2258
debasisdas
8,127 Expert 4TB
please check your code again.

some of your tables are dependent on each other like the customer and rentals table.so when you create the child table it will search for master table for estabnlishing the relationship, which is yet to be created .
to avoid this problem first create the tables then add the realtionships separately.
hope that helps you. if u stil have doubts please do post back.
Aug 18 '07 #2
antpal
3
please check your code again.

some of your tables are dependent on each other like the customer and rentals table.so when you create the chile table it will search for master table for estabnlishing the relationship, which is yet to be created .
to avoid this problem first create the tables then add the realtionships separately.
hope that helps you. if u stil have doubts please do post back.

Hi I fixed some code and rearranged my tables to the following:
--Create All Tables

CREATE TABLE authors (
auth_id NUMBER(7) PRIMARY KEY,
f_name VARCHAR2(30),
l_name VARCHAR2(50),
auth_specialty VARCHAR2(30)
);


CREATE TABLE books (
isbn CHAR (10) PRIMARY KEY,
title VARCHAR2 (50),
qty_owned NUMBER(3),
qty_on_hand NUMBER(3),
cost NUMBER,
location VARCHAR2(35),
auth_FK NUMBER CONSTRAINT books_auth_FK REFERENCES authors(auth_id)
);

CREATE TABLE book_details(
Num_Pages NUMBER(10),
copyright DATE,
publisher VARCHAR2(50),
category VARCHAR2(20),
isbn_nu_FK CHAR CONSTRAINT books_isbn_nu_FK REFERNECES books(isbn)
);

CREATE TABLE customer(
lib_card_id NUMBER(9) PRIMARY KEY, --no duplicates
f_name VARCHAR2(30),
l_name VARCHAR2(50),
num_str VARCHAR2(30),
city VARCHAR2(30),
zip VARCHAR2(7),
phone VARCHAR2(13),
card_start_date DATE,
card_exp_date DATE,
member_since DATE
);

CREATE TABLE rentals(
rental_id NUMBER(7) PRIMARY KEY,
isbn_nu_FK CHAR CONSTRAINT books_isbn_nu_FK REFERENCES books(isbn),
lib_card_FK NUMBER CONSTRAINT customer_lib_card_FK REFERENCES customer(lib_card_id),
employ_id_FK NUMBER CONSTRAINT employee_employ_id_FK REFERENCES employee(employee_id)
);

CREATE TABLE employee(
employee_id NUMBER(9) PRIMARY KEY,
f_name VARCHAR2(30),
l_name VARCHAR2(50),
num_str VARCHAR2(35),
city VARCHAR2(25),
state VARCHAR2(2),
zip VARCHAR2(5),
SSN VARCHAR2(9),
multi_lingual VARCHAR2(20),
ext VARCHAR2(3),
position VARCHAR2(25)
);

CREATE TABLE rental_details(
rental_id_FK NUMBER CONSTRAINT rentals_rental_id_FK REFERENCES rentals(rental_id),
isbn_num_FK CHAR CONSTRAINT books_isbn_num_FK REFERENCES books(isbn),
quanity NUMBER(5),
rental_date DATE,
due_date DATE
);


the only constraint problem I am having now is in book_details table for my foreign key constraint isbn_nu_FK. this is commingup as error and not sure why. If you could shed some light on this I'd greatly appreciate it. Thanks also for the Help before.
Aug 18 '07 #3
antpal
3
Nevermind I just figured it out I had a mispelling on references and also a duplicate FOREIGN KEY CONSTRAINT NAME.

Thanks Anyways
Aug 18 '07 #4
babind
3
hi this is anjan from hyd i saw ur programmes but i noticed some problem in that one
that is


CREATE TABLE books (
isbn CHAR (10) PRIMARY KEY,
title VARCHAR2 (50),
qty_owned NUMBER(3),
qty_on_hand NUMBER(3),
cost NUMBER,
location VARCHAR2(35),
auth_FK NUMBER CONSTRAINT books_auth_FK REFERENCES authors(auth_id)
);


CREATE TABLE rental_details(
rental_id_FK NUMBER CONSTRAINT rentals_rental_id_FK REFERENCES rentals(rental_id),
isbn_num_FK NUMBER CONSTRAINT books_isbn_num_FK REFERENCES books(isbn),
quanity NUMBER(5),
rental_date DATE,
due_date DATE,
);

in books table isbn column data type is char its ok
but rental_details table isbn_num datatype is num how can it takes char into num

first u mention both column datatype is same either char or number then try
i hope this time not get any error if u any error plz send me that error
i will try once again
but i hope this time not get any error
first u check all column datatype are match whos given references names of that then rectify erros


bye.........!










Nevermind I just figured it out I had a mispelling on references and also a duplicate FOREIGN KEY CONSTRAINT NAME.

Thanks Anyways
Aug 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
2
by: adammitchell | last post by:
How can you indicate that a FOREIGN KEY constraint references two columns in two different tables? "SQL Server Books Online" show an example of how to reference two columns in the SAME table:...
2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
22
by: Bradley | last post by:
Has anyone else noticed this problem? I converted the back-end to A2000 and the performance problem was fixed. We supply a 97 and 2000 version of our software so we kept the backend in A97 to make...
0
by: Megan | last post by:
Hi Everybody- I know that this is a really, really long post, but I wanted to try to give you as much background as possible. So here's a quick overview of the issues I'm asking for help with:...
2
by: Beacher | last post by:
Hello, I'm trying to create a relationship between two tables, a one to many tblDeal being the primary table, I'm trying to create a relationship between tblDeal and tblCondition .. i set...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
2
by: rorajoey | last post by:
Violation of UNIQUE KEY constraint 'IX_surveyQuestions'. Cannot insert duplicate key in object 'dbo.surveyQuestions'. This might seem like a simple matter of trying to insert a row with ID=20 when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.