Re: Duplicates

From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 10/16/04


Date: Sat, 16 Oct 2004 02:36:17 +0100

If you don't have a key in the customer table then you can't have a FOREIGN
KEY referencing it so I assume the foreign keys aren't actually declared
either. Anyway, here's how you can set the foreign key to reference the
first row for the customer, assuming you have some other column, such as
Customer Name, on which to join.

CREATE TABLE Customers (customer_no INTEGER NOT NULL, customer_name
VARCHAR(30) NOT NULL /* No PRIMARY KEY */)

CREATE TABLE foo (..., customer_no INTEGER)

UPDATE foo
 SET customer_no =
  (SELECT MIN(C2.customer_no)
   FROM Customers AS C1
   JOIN Customers AS C2
    ON C1.customer_name = C2.customer_name
     AND C1.customer_no = foo.customer_no)

-- 
David Portas
SQL Server MVP
--


Relevant Pages

  • Re: Table relationships
    ... Is it possible to create multiple foreign keys on a field in a table ... them in a table dedicated to prospects only. ... foreign key relationship to the Customer table. ... I won't get into design issues or concepts. ...
    (comp.databases.ms-access)
  • Re: Table relationships
    ... Is it possible to create multiple foreign keys on a field in a table ... I have an Invoice table where the Customer field is ... them in a table dedicated to prospects only. ... I won't get into design issues or concepts. ...
    (comp.databases.ms-access)
  • Re: Object/Relational Mapping is the Vietnam of Computer Sci
    ... We do such analyses in stock portfolio management, ... have to restore the entire customer object before I can then whittle ... Back references are established, where needed, similarly to foreign keys in RDBMSs. ... Over the years of such every-day-hundreds-of-ad-hoc analyses, I have not felt constrained to hierarchically navigate anything at all! ...
    (comp.lang.ruby)
  • Re: How to Relate Customers
    ... > it had 2 foreign keys, where both of them linked to the customerid in ... I did this so the Customer information would be ... Destination (FK references Companies) ... When you add the Companies table to the query grid for the second time, ...
    (microsoft.public.access.tablesdbdesign)

Loading