Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2007, 12:42 AM
Authorized User
 
Join Date: Jun 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default auto add foregin key to other table

i was created 2 table and specify the primary and foregin key, but the problem is i dont know how to do when i want to insert value to the supplier TABLE and in the same time the supplier_id will be auto add to the product TABLE. SO how to do that?

Example: two table

CREATE TABLE supplier
( supplier_id numeric(10) PRIMARY KEY not null,
 supplier_name varchar2(50) not null,
 contact_name varchar2(50),
 );

CREATE TABLE products
( product_id numeric(10) not null,
 supplier_id numeric(10) not null,
    FOREIGN KEY (supplier_id)
   REFERENCES supplier(supplier_id)
);




 
Old March 12th, 2007, 03:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need to look for writing a trigger on Supplier table for INSERT operation, so that when you add a new supplier, you can have it added to the Products table too.

Hope that helped.
Cheers

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Disable the "Shift Key" on macro Auto run ofAlexander Word VBA 1 June 24th, 2007 03:16 AM
auto increment primary key jcuga SQL Language 2 June 3rd, 2007 09:04 AM
SQL query to find key when auto-increment SandyFeder SQL Server ASP 1 November 21st, 2005 10:49 AM
How to auto increment primary key method SQL Server 2000 5 May 24th, 2005 03:25 PM
auto gerate of primary key Abhinav_jain_mca SQL Server 2000 15 October 1st, 2004 05:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.