Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi
i have two table, tablemain and tablesecond



In main table , the fieldname rollno have 20 record.

now i made tablesecond. , table second also have same field name rollno.

i need to update the rollno of table second from roll no of first table.

how i achieve this please help!
Posted

I cant change constraint,, can you give me sub query
No body is asking you to change any constraint. You have a wrong design and you are being asked to correct it. This clearly should be Foreign Key candidate.

Instead of trying to update/correct the rollno field in both tables everytime, you should fix the table design and make sure that main table rollno is a foreign key of tablesecond.

Still, if you want to update roll no from table 1 to table 2, then first you need to get the missing rollno in table2 and then insert them.
SQL
Select Rollno FROM mainTable Where rollno NOT IN (Select Rollno from TableSecond)

Either in SP or code, you need to loop through these rollno to insert and match the two tables.
 
Share this answer
 
Use Foreign Key concept u'll be able to solve your problem. make sure the rollno column of first table is made as primary key.
 
Share this answer
 
Comments
balongi 14-Jul-12 3:54am    
I cant change constraint,, can you give me sub query
use AFTER UPDATE Trigger/AFTRE INSERT Trigger for this problem
for more detail for trigger look this Article[^]
 
Share this answer
 
v3

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