469,356 Members | 2,003 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Procedure for deleting records

Hi

I have created two tables 'TrainsMaster' & 'TransArrvlDepinfo'

Columns which I have created in 'TrainsMaster' are 'trainName,TrainNo, StartStaionId, & EndstationId'

Columns which I have created in ''TransArrvlDepinfo' are 'Stationcode, TrainNo, Arrvaltime,Depttime'

I have to delete few trains from 'TrainsMaster' for which the Startstationid or Endstationid are nulls which comes to 50 records

The above said null valued trains should be removed form ''TransArrvlDepinfo' table as well.

For example I have the following trains to be deleted from 'TrainsMaster'

Train Name Train No Startstionid endstationid
Yeshvantpur - Guwahati Express 201 NULL GHY
Jammutawi AC Special 905 NULL JAT
Amritsar AC Special 951 NULL ASR
Delhi - Howrah Special 232 NULL HWH

When I check the above trains in 'TransArrvlDepinfo' table there are lot of trains which passes through the staioncode 'ghy'

For example 'GHY' is the station code in which lots of trains run through. I need a procedure for deleting the above said trains with the same station code. i.e. I should be deleting only train no 201 for which the station code is 'ghy' similarly the above said trains should be deleted from 'TransArrvlDepinfo' table with their corresponding stationcodes.

Please give the procedure for deleting multiple records
Sep 17 '08 #1
2 1750
deepuv04
227 Expert 100+
Hi,
First you need to delete records from table TransArrvlDepinfo, and then delete from table TrainsMaster

use the following code:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE DeleteTrainInfo
  2. AS
  3. BEGIN
  4.     -- Delete records from  TransArrvlDepinfo
  5.     DELETE FROM TransArrvlDepinfo
  6.     FROM TransArrvlDepinfo INNER JOIN
  7.          TrainsMaster ON TrainsMaster.TrainNo = TransArrvlDepinfo.TrainNo
  8.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  9.  
  10.     -- Delete records from TrainsMaster
  11.     DELETE FROM TrainsMaster
  12.     FROM TrainsMaster
  13.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  14. END
  15.  
To delete a specific train info pass train no as parameter and use it in where clause.
Thanks
Sep 17 '08 #2
Hi Thanks for your help.

Hi,
First you need to delete records from table TransArrvlDepinfo, and then delete from table TrainsMaster

use the following code:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE DeleteTrainInfo
  2. AS
  3. BEGIN
  4.     -- Delete records from  TransArrvlDepinfo
  5.     DELETE FROM TransArrvlDepinfo
  6.     FROM TransArrvlDepinfo INNER JOIN
  7.          TrainsMaster ON TrainsMaster.TrainNo = TransArrvlDepinfo.TrainNo
  8.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  9.  
  10.     -- Delete records from TrainsMaster
  11.     DELETE FROM TrainsMaster
  12.     FROM TrainsMaster
  13.     WHERE (TrainsMaster.Startstationid IS NULL OR TrainsMaster.Endstationid IS NULL)
  14. END
  15.  
To delete a specific train info pass train no as parameter and use it in where clause.
Thanks
Sep 17 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by deprins | last post: by
5 posts views Thread by Mojtaba Faridzad | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.