Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3970126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:02:56+00:00 2026-05-20T04:02:56+00:00

I am in this situation: I have two tables, where one is the table

  • 0

I am in this situation: I have two tables, where one is the table containing a list of songs, the other contains a list of artists.
Each row of the song table contains a reference to one artist (one row of the artist table).
I would like to write a trigger that, after an update or after a deletion on the songs table, checks if an artist is not referenced by any song any more and delete it in case it is necessary. This way I can have a clean database where I have no unused artists. Is this possible? How can I accomplish this?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:02:57+00:00Added an answer on May 20, 2026 at 4:02 am

    of course it is possible 😉

    I don’t know the exact syntax for sqlite, but try this :

    create trigger trigger_name 
    after delete, update on artists_table
    for each row
    begin
    
    delete from artists_table where artists_id = old.artists_id
        where (select count(*) from songs where artists_id = old.artists_id) = 0;
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the situation: I have two tables where the one references the other
This is my situation. I have two activities: ONE and TWO. In TWO activity
I have a one-to-many relationship between two classes for this situation. I have a
I have two database tables, one for Users of a web site, containing the
Just after some advice regarding this database design situation. So I have two tables
I have two tables one named Person , which contains columns ID and Name
Let me explain the situation I have two tables: -One is to store the
In this situation I have two models, Comment and Score. The relationship is defined
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I have this situation where I want to display a list of Administration objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.