Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Constraint problem

 
   Database Forums (Home) -> Ingres RSS
Next:  Using san with SQL server  
Author Message
--CELKO--

External


Since: Apr 17, 2007
Posts: 417



(Msg. 1) Posted: Wed Oct 28, 2009 6:23 pm
Post subject: Constraint problem
Archived from groups: comp>databases>ingres (more info?)

This is an actual problem in a manufacturing environment. An order
goes to one and only one customer. An order will have products that
are specified by either the customer or by us; there are no other
sources. We use DUNS numbers to identify companies, both customers
and ourselves (assume our DUNS = '999999999'); there are no other
sources.

The skeletons of the tables involved look like this:

CREATE TABLE Orders
(order_nbr INTEGER NOT NULL PRIMARY KEY,
customer_duns_nbr CHAR(9) NOT NULL
REFERENCES Companies (duns_nbr),
…);


CREATE TABLE Order_Details
(order_nbr INTEGER NOT NULL
REFERENCES Orders(order_nbr)
ON UPDATE CASCADE
ON DELETE CASCADE,
item_nbr INTEGER NOT NULL,
PRIMARY KEY (order_nbr, item_nbr)
specifier_duns_nbr CHAR(9) NOT NULL,
REFERENCES Companies (duns_nbr),
…);

What is the best way to enforce the constraint which we could write in
Full-92 as a table constraint:

CHECK (specifier_duns_nbr
IN ((SELECT customer_duns_nbr
FROM Orders AS O
WHERE O.order_nbr = Order_Details.order_nbr),
'999999999')

 >> Stay informed about: Constraint problem 
Back to top
Login to vote
Karl Schendel

External


Since: Apr 19, 2004
Posts: 17



(Msg. 2) Posted: Thu Oct 29, 2009 6:30 am
Post subject: Re: [Info-Ingres] Constraint problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Oct 28, 2009, at 9:23 PM, --CELKO-- wrote:

> [snip]
> specifier_duns_nbr CHAR(9) NOT NULL,
> REFERENCES Companies (duns_nbr),
> …);
>
> What is the best way to enforce the constraint which we could write in
> Full-92 as a table constraint:
>
> CHECK (specifier_duns_nbr
> IN ((SELECT customer_duns_nbr
> FROM Orders AS O
> WHERE O.order_nbr = Order_Details.order_nbr),
> '999999999')

In Ingres? probably the best way is to create an insert/update
rule on order_details, passing specifier_duns_nbr and
order_nbr to the DBP. The DB procedure would execute
a select similar to your constraint, and RAISE ERROR if the
condition is not met.

Karl

 >> Stay informed about: Constraint problem 
Back to top
Login to vote
--CELKO--

External


Since: Apr 17, 2007
Posts: 417



(Msg. 3) Posted: Thu Oct 29, 2009 7:52 am
Post subject: Re: Constraint problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

That was one answer I came up with. In Standard SQL, it would have
been a CREATE ASSERTION statement, since it involves a table level
query. The other was a TRIGGER.
 >> Stay informed about: Constraint problem 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
unique constraint or primary key ? - I've been asked by a user to prevent duplicate rows in a table. What is the best way ? It's a small table with only 60 rows and two columns. col1 must be unique.

[Info-Ingres] Unique constraints and journaling - Hi Everyone, I'm running IngresIIR3 patch 11577. I have a database (journalled), a table (journalled) on which I'm applying constraints of various types. The PK, FK and Check constraints are all happy to be applied but the unique constraint fails ..

Problem with check - Hello, I want to make such instruction from MySQL in Ingres. credit_rating ENUM('EXCELLENT','GOOD','POOR'); I have no idea how to do it. I was searching in e-books of Ingres by only what i found is somethingwith word check. Thanks for help Regards,..

Problem with copy.in - I am trying to reload some data that I exported with a modified copy.out script. But I get the following error: E_US14E4 Invalid options have been specified for a non fast-load COPY. Invalid options are: FILLFACTOR, MINPAGES, MAXPAGES,..

Having problem with simple "NOT IN" query - Hello all, I have two tables tab_a id(int) tab_b id(int) and I try the following select which returns an error: SELECT id from tab_a where id NOT IN (select id from tab_b); #1064 - You have an error in your SQL syntax. Check the manual that..
   Database Forums (Home) -> Ingres All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]