Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have two tables

SQL
TABLE - projectpaymentschedule

COLUMN - ppsID(primary key,auto increment),milestone,completiondate,billingdate,billingrupee,projectid

TABLE - projectpaymentreceipt

COLUMN - pprID(primary key,auto increment),receiptdate,receiptamount,projectid,ppsID(Foreign key)


how to make foreign key in second table and i want when i insert data in first table automatically ppsID value inserted in second table.

Thanks in Advance.
Posted
Updated 17-Apr-12 19:48pm
v2
Comments
Sergey Alexandrovich Kryukov 18-Apr-12 1:46am    
It has nothing to do with ASP.NET. Did you mean ADO.NET?
--SA
mayankshrivastava 18-Apr-12 1:48am    
ya sory i want in ado.net or sql server

Try this:
SQL
TABLE - projectpaymentschedule

COLUMN - ppsID(primary key,auto increment),milestone,completiondate,billingdate,billingrupee,projectid

TABLE - projectpaymentreceipt

COLUMN - pprID(primary key,auto increment),receiptdate,receiptamount,projectid,ppsID FOREIGN KEY REFERENCES(ppsID)


Have a look on following threads:
Creating Primary & Foreign keys[^]
SQL-Foreign key[^]
 
Share this answer
 
v2
Comments
mayankshrivastava 18-Apr-12 1:52am    
how to write this,
actually i don't no more about foreign key.
Prasad_Kulkarni 18-Apr-12 1:57am    
Please see updated answer followed by some links..
mayankshrivastava 18-Apr-12 2:05am    
I followed your links and made a foreign key.
But when i insert data in first table ppsID in not insert into second table.
is there any code write in insert query of first table ?
In ADo.Net you need to setup data constraints[^].
The System.Data.DataSet.EnforceConstraints property should be set to true.

Using the Cascade option will allow changes to be cascaded to related tables.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900