0

hi

i have a simple relationship which is shown in the link below

http://www.flickr.co...N06/6948010043/

after doing much research i cannot find a proper way of deleting rows which are linked in all 3 tables.

could someone guide me on the best way of doing this.

This is the code i am using currently :

strsql = "delete *  from  cg_security_user_right  where user_id=@field1 &  right_id=@field2  "
        Dim objcmd As New System.Data.OleDb.OleDbCommand(strsql, acsconn) ' the oledbcommand
        With objcmd
            .Parameters.AddWithValue("@field1", TextBox1.Text)
            .Parameters.AddWithValue("@field2", TextBox2.Text)



        End With
        Dim result As Integer = 0
        result = objcmd.ExecuteNonQuery()
        objcmd.Dispose()
        MsgBox(result & " Row Deleted")
    End Sub
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by 0x90
0

Could you repost the link? It appears to have been malformed when you've posted it so I can't actually see the linkage.

I've taken a guess and I'm assuming you want to delete the records from one table if it is linked to from the other two tables. If that is the case, the below query should work for you, you'll just have to replace the fields it joins on and of course put in the table names:

DELETE t1 FROM
	table_1 t1
INNER JOIN
	table_2 t2 ON t1.user_id = t2.user_id
INNER JOIN
	table_3 t3 ON t1.user_id = t3.user_id

Hope that helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.