Re: Duplicates
From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 10/16/04
- Next message: Wisam: "SqlDumpExceptionHandler: Process 52 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION"
- Previous message: David Portas: "Re: Script a Table content?"
- In reply to: ennovations: "Duplicates"
- Messages sorted by: [ date ] [ thread ]
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 --
- Next message: Wisam: "SqlDumpExceptionHandler: Process 52 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION"
- Previous message: David Portas: "Re: Script a Table content?"
- In reply to: ennovations: "Duplicates"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|