Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 8th, 2008, 01:34 PM
Trogan Trogan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 9 Trogan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 38 sec
Reputation Power: 0
Constraints Help Please

Hi,

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

Here are the tables I have created.

Quote:
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...
Quote:
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 or a possible solution?

Any solution or advice would be greatly appreciated.

Thank you!

Reply With Quote
  #2  
Old April 8th, 2008, 03:11 PM
LKBrwn_DBA LKBrwn_DBA is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 294 LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 16 h 48 m 15 sec
Reputation Power: 9
Cool

When you have a Primary Key/Unique Key constraint, that means only distinct values are allowed (no duplicates).

The purpose of these constraints is to NOT ALLOW you to enter duplicate invoice numbers!
__________________

Reply With Quote
  #3  
Old April 8th, 2008, 03:29 PM
Trogan Trogan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 9 Trogan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 38 sec
Reputation Power: 0
I understand that.

Is there a solution, then, for what I need to do? Is there a way to modify my tables to make this work?

Thanks for the reply.

Reply With Quote
  #4  
Old April 9th, 2008, 08:25 AM
LKBrwn_DBA LKBrwn_DBA is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 294 LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 16 h 48 m 15 sec
Reputation Power: 9
Thumbs down

The only way to enter duplicate invoice numbers would be to disable/drop the primary key and related foreign constraints.

This would be unacceptable and compromise the integrity of the data.


Reply With Quote
  #5  
Old April 9th, 2008, 04:23 PM
Trogan Trogan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 9 Trogan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 38 sec
Reputation Power: 0
I made some minor changes to my tables and managed to get things working.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Constraints Help Please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway