SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 22nd, 2003, 01:59 PM
^devil^ ^devil^ is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 34 ^devil^ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Help on Delete

hi all

currently i have two table ,
1st table ( tblcompetency )
Code( as primary Key) , Name

2nd table qno ( as primary key) , qdescription and Code(as foreign key of tblcompetency)

both table are link as one to many relationship ( one competency can have many question)

my problem is that how do i delete the entire record whereby when user Key in Code( eg cna-1001)
it will delete the Code record in tblcompetency table
and delete the record where = code in tblqns table

i am puzzled , help !

Cheers ~

Reply With Quote
  #2  
Old December 22nd, 2003, 02:25 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Are you doing this in some type of application??? VB, ASP, .NET???

Reply With Quote
  #3  
Old December 22nd, 2003, 10:08 PM
^devil^ ^devil^ is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 34 ^devil^ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Yes i am currently doing a project on ASP.net

Reply With Quote
  #4  
Old December 23rd, 2003, 10:17 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
well, you could create a stored procedure (assuming you are using Sql Server), that would take the Code as the input parameter and then run the delete statements against the 2 tables.
Code:
CREATE PROCEDURE stp_RemoveRecordsByCode
      @Code varchar(20)
AS
DELETE 
FROM tblCompetency
WHERE Code = Cast(@Code As int)

DELETE
FROM Table2
WHERE Code = Cast(@Code As int)

GO


and then just call it from your application passing it the Code

Or

Just write the code to delete it from both tables

Code:
Dim Conn As SqlConnection
Dim Cmd As SqlCommand
Dim strSQL As String
Dim reader As SqlReader

Conn = New SqlConnection("server=servername;User ID=username;PWD=password;database=dbname")
strSQL = "DELETE FROM tblCompetency WHERE Code = " & Code 

Cmd = New SqlCommand(strSQL, Conn)

Try
   Conn.Open()
   reader = Cmd.ExecuteNonQuery()
   reader.Close()

   strSQL = "DELETE FROM table2 WHERE Code = " & Code
   Cmd = New SqlCommand(strSQL, Conn)
   reader.ExecuteNonQuery()

  reader.Close()
  Conn.Close()
Catch ex As Exception
   Response.write("Error: " & ex.Message())
End Try

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Help on Delete


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT