General information
Forum:
Microsoft SQL Server
>Can somebody give me a run down on how to create a one to many relationship in SQL 7.0. You know the classic "One Invoice has many items"
>
>INVHD.Number has many INVITEMS.Number ?
>
>Thanks
You really don't need to any thing special except create the two related tables. But, what I think you want to know is how to set it up so the SQL Server knows about the relationship and does some policing of it.
What you want to do is add a Foreign Key constraint to the child table. In your example... lets say the Invoice table has a PK of InvoiceID and the InvoiceDetail table has a FK or InvoiceID... send a command like this...
ALTER TABLE InvoiceDetail ADD CONSTRAINT InvoiceID
FOREIGN KEY (InvoiceID) REFERENCES Invoice(InvoiceID)
HTH,
BOb
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only