Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
DECLARE @mid bigint, @tid bigint,@lastid bigint

select top 1 @mid=Identifier from tbl_Identifier where StatusID='6' and PoolID='5001'

set @lastid=@mid+5000

select top 1 @tid=Identifier from tbl_Identifier where StatusID='6' and PoolID='5002'


WHILE (@mid <= @lastid)
BEGIN

 insert into tbl_Reserved(M_IID,T_IID) values(@mid,@tid)
    SELECT @tid=@tid+1
 insert into tbl_Reserved(M_IID,T_IID) values(@mid,@tid)
     SELECT @mid = @mid + 1

Posted

1 solution

It means that there is forced-relation between the two tables. You can not insert value into tbl_Reserved that not in tbl_Identifier...
 
Share this answer
 
Comments
Naresh1277 2-Jan-14 8:47am    
if i do go with order by desc in the end,will it be supressing the err ??
select top 1 @mid=Identifier from tbl_Identifier where StatusID='6' and PoolID='5001' order by identifier desc
Kornfeld Eliyahu Peter 2-Jan-14 8:57am    
I didn't got you. What the connection between the select at the beginning and the insert at the end?!
The problem is that the insert try to add records with invalid values in it...
See the values in @tid and see the values in tbl_Identifier...
Naresh1277 2-Jan-14 8:59am    
Can you guide me on this further ??unable to understand the issue
could please
Kornfeld Eliyahu Peter 2-Jan-14 9:53am    
I'm trying to explain that foreign-key is to ensure data integrity in that way that you can't insert value to table A that not declared in table B.
If you can explain me - in plain English - what you try to do I may able to help you further...
Naresh1277 7-Jan-14 3:45am    
Hey Peter !! I got it man thanks allot!! i have changed the table schema

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