Re: How to make a Foreing Key?

From: Jesus Cardenas (jesusc_at_tfs.grupo-ed.com)
Date: 10/15/04


Date: Fri, 15 Oct 2004 09:13:40 -0500

Hi John, below are the code DDL ,

Supose I have this tables DETAIL, HEADER and ITEMS and I want to add in the
table DETAIL a Foreing Key ITEMS.CUSTOMER , ITEMS.PRODUCT but I can't do
this. Because in the DETAIL table I don't have the field CUSTOMER

Should I ADD a field CUSTOMER in the table DETAIL to do that? or Is there
any another beter way?

Thanks!

CREATE TABLE [dbo].[detail] (
 [entry] [int] NOT NULL ,
 [line] [int] NOT NULL ,
 [product] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[header] (
 [entry] [int] NOT NULL ,
 [customer] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[items] (
 [customer] [int] NOT NULL ,
 [product] [int] NOT NULL ,
 [description] [varchar] (50) NULL
) ON [PRIMARY]
GO

"John Bell" <JohnBell@discussions.microsoft.com> wrote in message
news:55265E7B-28FF-4C13-8B8F-D684C6BD5161@microsoft.com...
> Hi
>
> Unfortunately your question is not that clear! Your column names are not
> obvious and without furhter knowledge of your system it is hard to answer.
> Posting DDL is always a lot clearer than pseudo code in this kind of
> situation http://www.aspfaq.com/etiquette.asp?id=5006
>
> If you have a master/detail situation, then you would normally have the
> master PK as part of a composite PK in the detail table. Your detail/items
> table seem to be trying to do the same thing.
>
>
> John
>
> "Jesus Cardenas" wrote:
>
> > I've this tables
> >
> > Header
> > entry
> > customer
> > ....
> >
> > Detail
> > entry
> > line
> > partnumber
> > ....
> >
> > Items
> > customer
> > partnumber
> > description
> >
> > How can I make a Relationships Detail - Item when I don't have the field
> > customer in the table Detail
> >
> > I've MSSQL 7
> >
> > I hope the cuestin is clear...
> >
> > Thanks in advance ...
> >
> >
> >



Relevant Pages

  • [PATCH 10/21] mm: page fault handlers tidyup
    ... Impose a little more consistency on the page fault handlers do_wp_page, ... * We hold the mm semaphore and the page_table_lock on entry and exit ... return ret; ... -static int do_swap_page(struct mm_struct * mm, ...
    (Linux-Kernel)
  • Re: BIG BUG in Deleting detali records
    ... in the database in order to enforce referential integrity. ... when the customer himself is deleted from the master table. ... customerID int identity not null primary key, ...
    (borland.public.delphi.database.ado)
  • Lock-free hash table
    ... C implementation of Cliff Click's lock-free hash table. ... unsigned int scale; ... // Record if the entry being returned is empty. ... return hti; ...
    (comp.programming.threads)
  • Re: writing strings instead of rabish to file using fprintf
    ... > please and help me finding the reason why this rabish is being ... use either int or unsigned ... And similarly with customer number. ... FAQ below. ...
    (comp.lang.c)
  • Re: Database Design Problem
    ... at your design that you would lose ProductCategoryID from the Orders table ... You should also have a customer and employee table and only include ... [EmployeeID [INT] ... You would also have primarykeys on OrderID in ORders and SerialNumber in ...
    (microsoft.public.sqlserver.programming)