By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,651 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,651 IT Pros & Developers. It's quick & easy.

Procedure for deleting records

P: 17
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
Share this Question
Share on Google+
2 Replies


deepuv04
Expert 100+
P: 227
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

P: 17
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.