Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Deleting using InnerJoin

Deleting using InnerJoin

Scheduled Pinned Locked Moved Database
helpsharepoint
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dayakar_dn
    wrote on last edited by
    #1

    Hi, I am having two table which are related with primary and foreign key constraints. I want to delete records from both the tables using innerjoin. I applied like this, delete sports,studentregtable from studentregtable as sr INNER JOIN sports sp ON sr.registerNo = sp.RegisterNumber where RegisterNumber = '123' but it is giving an error like incorrect syntax near ",". can you please help me if you know the solution.

    C D 2 Replies Last reply
    0
    • D dayakar_dn

      Hi, I am having two table which are related with primary and foreign key constraints. I want to delete records from both the tables using innerjoin. I applied like this, delete sports,studentregtable from studentregtable as sr INNER JOIN sports sp ON sr.registerNo = sp.RegisterNumber where RegisterNumber = '123' but it is giving an error like incorrect syntax near ",". can you please help me if you know the solution.

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      You have to delete from each table separately. Try the following

      delete from studentregtable where registerNo = '123';
      delete from sports where RegisterNumber = '123';

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

      S 1 Reply Last reply
      0
      • C Chris Meech

        You have to delete from each table separately. Try the following

        delete from studentregtable where registerNo = '123';
        delete from sports where RegisterNumber = '123';

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

        S Offline
        S Offline
        SilimSayo
        wrote on last edited by
        #3

        If one of the tables has a foreign refencing the other table, start with the table with the foreign key.

        1 Reply Last reply
        0
        • D dayakar_dn

          Hi, I am having two table which are related with primary and foreign key constraints. I want to delete records from both the tables using innerjoin. I applied like this, delete sports,studentregtable from studentregtable as sr INNER JOIN sports sp ON sr.registerNo = sp.RegisterNumber where RegisterNumber = '123' but it is giving an error like incorrect syntax near ",". can you please help me if you know the solution.

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          If this is SQL Server, you can specify to cascade deletes when you create the foreign key constraint. Then, you can delete from the parent table and the database will automatically delete the corresponding rows from the child table. Personally, I don't like this because it makes me feel as if I'm not in control and I get nervous when the DBMS does things behind my back like that. But some people swear by it, so YMMV. Sybase and DB2 both have this same cascade ability on a foreign key; not sure about Oracle but I guess it probably does.

          N 1 Reply Last reply
          0
          • D David Skelly

            If this is SQL Server, you can specify to cascade deletes when you create the foreign key constraint. Then, you can delete from the parent table and the database will automatically delete the corresponding rows from the child table. Personally, I don't like this because it makes me feel as if I'm not in control and I get nervous when the DBMS does things behind my back like that. But some people swear by it, so YMMV. Sybase and DB2 both have this same cascade ability on a foreign key; not sure about Oracle but I guess it probably does.

            N Offline
            N Offline
            nagendrathecoder
            wrote on last edited by
            #5

            Yes, it does. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups