473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2096
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

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

Similar topics

2
by: Subodh | last post by:
HI, I need to run same kind of transactions (basically deleting records) in a loop but I have only 1 hour in a day to run my procedure. So I need to set a timer in a SP so that SP terminates...
4
by: deprins | last post by:
Hello, I have wrote a stored procedure but its real slow. Its activated by a button on web page but its takes to long to process and the web server gives a timeout message after 5 minutes. Is...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
0
by: jobs | last post by:
I have a gridview that I use to both select a record to be edited in a formview and to also delete records with. Because the selectcommand is grouping rows, my deletes stored procedure requires a...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
2
by: Deepamathi | last post by:
Thanks in advance for your help. I need a Stored Procedure that will do the following steps: 1. delete a single record from table GROUP 2. delete all records from table SUBGROUP with a matching...
3
by: gaurim | last post by:
I am facing the coding proble in the following Stored Procedure wherein I am trying to create a table after deleting it. and then I am trying to insert records from two other tables based on certain...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.