473,564 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Procedure for deleting records

17 New Member
Hi

I have created two tables 'TrainsMaster' & 'TransArrvlDepi nfo'

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

Columns which I have created in ''TransArrvlDep info' are 'Stationcode, TrainNo, Arrvaltime,Dept time'

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 ''TransArrvlDep info' 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 'TransArrvlDepi nfo' 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 'TransArrvlDepi nfo' table with their corresponding stationcodes.

Please give the procedure for deleting multiple records
Sep 17 '08 #1
2 2105
deepuv04
227 Recognized Expert New Member
Hi,
First you need to delete records from table TransArrvlDepin fo, 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
padmaneha
17 New Member
Hi Thanks for your help.

Hi,
First you need to delete records from table TransArrvlDepin fo, 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
7031
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 after one hour and then rest of the transactions will be done next day. Can anybody suggest as how to check execution time in a stored procedure? The...
4
6227
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 there anyway to speed up this stored procedure? What am I doing wrong here? ...
1
6097
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 records in the subform? I have tried undoing both the main form and the subform and I have tried deleting the record in the main form. Thanks! ...
1
2383
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 about 80 records from the Orders table. 80 out of a 1000 records. Now our data entry form shows our customer addresses, but not customer order...
5
14722
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 trying to delete these lines from the dataview like this: for (int i=0; i < dataView.Count; i++) if (dataGrid.IsSelected(i)) dataView.Delete(i);
0
1508
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 different set of keys than the one used for the edit. The datakeyname in my gridview has a key I need for editing that I do not need for...
11
3654
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) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From...
2
9457
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 'groupID' from the deleted GROUP 2. as each record from SUBGROUP is deleted there are multiple associated records in the table...
3
1968
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 condition. I am getting error(s) in it. Can someone help me in solving it. Regards ===================================================== ...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.