User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 361,943 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,690 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser:
Views: 450 | Replies: 9
Reply
Join Date: Mar 2008
Posts: 5
Reputation: Trogan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Trogan Trogan is offline Offline
Newbie Poster

Constraint Help Please

  #1  
Apr 8th, 2008
Hi,

I have some tables (below), but I'm having trouble entering multiple lines of data.

Here are the tables I have created.

CUSTOMER table
SQL> create table customer
2 (customer_no char(6) not null,
3 name varchar2(30) not null,
4 address varchar2(50) not null,
5 credit_limit number(6,2),
6 constraint customer_customer_no_pk primary key (customer_no));

Table created.

SALESMAN table
SQL> create table salesman
2 (salesman_id char(8),
3 name varchar2(20) not null,
4 address varchar2(50) not null,
5 emaill_address varchar2(30),
6 constraint salesman_salesman_id_pk primary key (salesman_id));

Table created.

ITEM table
SQL> create table item
2 (ISBN char(13) not null,
3 title varchar2(30) not null,
4 price number(4,2) not null,
5 constraint item_ISBN_pk primary key (ISBN));

Table created.

INVOICE table
SQL> create table invoice
2 (invoice_no char(1) not null,
3 invoice_date date not null,
4 salesman_id char(8),
5 customer_no char(6) not null,
6 ISBN char(13) not null,
7 Nos varchar2(2) not null,
8 credit_limit number(6,2),
9 payment_type varchar2(6) not null,
10 constraint invoice_invoice_no_pk primary key (invoice_no),
11 constraint invoice_salesman_id_fk foreign key (salesman_id)
12 references salesman(salesman_id),
13 constraint invoice_customer_no_fk foreign key (customer_no)
14 references customer(customer_no),
15 constraint invoice_ISBN_fk foreign key (ISBN)
16 references item(ISBN));

Table created.

DELIVERY table
SQL> create table delivery
2 (invoice_no char(1) not null,
3 ISBN char(13) not null,
4 constraint delivery_invoice_no_ISBN_cpk primary key (invoice_no,ISBN),
5 constraint delivery_invoice_fk foreign key (invoice_no)
6 references invoice(invoice_no),
7 constraint delivery_ISBN_fk foreign key (ISBN)
8 references item(ISBN));

Table created.

I can enter data into the customer, salesman and item table without any problems. However, I need to enter multiple lines of data using the same invoice_no (which is 1). The data is generally the same, except for 2 things need changing but I keep getting the following error...

ORA-00001: unique constraint (SYSTEM.INVOICE_INVOICE_NO_PK) violated

I understand that I can only use invoice_no once since it is a unique key.

Is there a way of getting around this problem?

Any solution or advice would be greatly appreciated. Thank you!

I am also fairly new to database systems.
Last edited by Trogan : Apr 8th, 2008 at 2:25 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: UAE
Posts: 399
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Whiz

Re: Constraint Help Please

  #2  
Apr 9th, 2008
<_<

Remove the PK (invoice_no, ISBN) from the Delivery table so that you can repeat the invoice_no as much as you want.

Think of a new PK for the detail (delivery) table. How about Serial no?
Reply With Quote  
Join Date: Mar 2008
Posts: 5
Reputation: Trogan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Trogan Trogan is offline Offline
Newbie Poster

Re: Constraint Help Please

  #3  
Apr 9th, 2008
Hi Sulley, thank you for the reply.

I will remove the PK (invoice_no, ISBN) from the Delivery table and put something in it's place and see how it goes.

Thanks again!
Reply With Quote  
Join Date: Mar 2008
Posts: 5
Reputation: Trogan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Trogan Trogan is offline Offline
Newbie Poster

Re: Constraint Help Please

  #4  
Apr 9th, 2008
It didn't work.

I should have mentioned, I need to enter multiple data into the invoice table using the same invoice_no.

Any other suggestions please?
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,576
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 184
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Constraint Help Please

  #5  
Apr 9th, 2008
So you've made a serious error in your datamodel.
Apparently a record in the invoice table does not represent an invoice but a line item.
Redesign your database to match that, with a new invoice table containing only items that are not repeated (like the invoice number), and a lineitem table containing a foreign key into to the invoice table to the invoice number.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Dec 2004
Location: UAE
Posts: 399
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Whiz

Re: Constraint Help Please

  #6  
Apr 9th, 2008
You can overcome that problem by having a composite key (2 PKs) for the invoice table .. where you'll be able to repeat the invoice number BUT not the other Primary key ..

Can you show us your ERD?
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,576
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 184
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Constraint Help Please

  #7  
Apr 9th, 2008
yes, but that would leave you with a substandard database model.
You'd have to duplicate data in each record, a bad idea.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Dec 2004
Location: UAE
Posts: 399
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Whiz

Re: Constraint Help Please

  #8  
Apr 10th, 2008
<_<

do what jwenting said .. 1 master table (invoice) and a transaction table linked to it (one to many relationship) ..
Reply With Quote  
Join Date: Mar 2008
Posts: 5
Reputation: Trogan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Trogan Trogan is offline Offline
Newbie Poster

Re: Constraint Help Please

  #9  
Apr 15th, 2008
Forgot to reply, but I managed to get things working by making some minor changes to the tables.
Reply With Quote  
Join Date: Apr 2008
Location: India
Posts: 11
Reputation: jinternalframe is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
jinternalframe's Avatar
jinternalframe jinternalframe is offline Offline
Newbie Poster

Re: Constraint Help Please

  #10  
Apr 17th, 2008
Hey good that you made your stuff work. But keep in mind this thing - The databases are only the repositoires of data. It is you who will have to decide what data goes in where and make sure that you use the capabilities of the database to reflect the exact needs of your data model (your data). Making ad-hoc changes might work bu they may not be fruitful in the long run. Also, analyse the model before you even try to create any tables in the database. That will definitely help in the long run.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Oracle Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Oracle Forum

All times are GMT -4. The time now is 11:39 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC