Hi
I need a help
I create a table
Table 1
(
Id int primary key Identity(1,1) not null,
Name varchar (100),
NoofBoxes int
)
Table 2
(
Boxes_Id int Primary key Idenity(1,1) not null,
Name varchar (100),
)
I want that When I insert value in Table 1 that NoofBoxes is 10 then in Table 2 10 rows has been Inserted ,
I face A problem
when I Update table 1 NoofBoxes from 10 to 8 then I need that 2 rows deleted from table 2 and when I Update table 1 from 10 to 15 then I need 5 more rows in table 2
Loading

Amitesh VermaPosted Aug 3, 2015, 8:49 AM
create table #Table1
(
Id int primary key Identity(1,1),
Name varchar(100),
NoofBoxes int
)
drop table #Table2
create table #Table2
(
Boxes_Id int Primary key identity(1,1),
Name varchar(100)
)
insert into #Table1(Name,NoofBoxes) values('a',2)
insert into #Table1(Name,NoofBoxes) values('b',3)
insert into #Table1(Name,NoofBoxes) values('c',3)
insert into #Table1(Name,NoofBoxes) values('d',5)
insert into #Table1(Name,NoofBoxes) values('e',4)
insert into #Table1(Name,NoofBoxes) values('r',4)
insert into #Table1(Name,NoofBoxes) values('h',4)
insert into #Table1(Name,NoofBoxes) values('rd',6)
insert into #Table1(Name,NoofBoxes) values('d',6)
insert into #Table1(Name,NoofBoxes) values('d',9)
select * from #Table1
insert into #Table2 values('h')
insert into #Table2 values('f')
insert into #Table2 values('fe')
insert into #Table2 values('df')
insert into #Table2 values('d')
insert into #Table2 values('gd')
insert into #Table2 values('gd')
insert into #Table2 values('gd')
insert into #Table2 values('gd')
insert into #Table2 values('gdf')
insert into #Table2 values('gfd')
select * from #Table2
update #Table1 set NoofBoxes=10
select * from #Table1
select * from #Table2
update #Table1 set NoofBoxes=15
select * from #Table1
select * from #Table2
Raja TPosted Aug 3, 2015, 8:46 AM