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 8226551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:48:35+00:00 2026-06-07T15:48:35+00:00

Can you show sample coding to create a trigger or stored procedure that maintains

  • 0

Can you show sample coding to create a trigger or stored procedure that maintains rows a SQL Server junction table when changes are made to the Authors and BookTitles tables such as inserting and updating rows in those tables?

We have the following tables:

Authors:
ID
NAME
ZIP
AND SOME MORE COLUMNS

BookTitles:
ID
TITLE
ISBN
AND SOME MORE COLUMNS

This is the table we will use as our junction table:

AuthorTitles:
ID
AUTHOR_ID
BOOK_TITLE_ID

We would like to do this in a trigger instead of doing the coding in our VB.Net form.

All help will be appreciated.

The above table structures were simplified to show what we are trying to do.

We are implementing a junction table for teachers and programs.

Here is a photo of the actual system:

  • 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-06-07T15:48:38+00:00Added an answer on June 7, 2026 at 3:48 pm

    Unless you have Foreign Key constraints that require at least one Book per Author and/or vice-versa, then the only cases that you should need special handling are for the Deletes to BookTitles or Authors. They can be done like this:

    CREATE PROC BookTitle_Delete(@Book_ID As INT) As
     -- First remove any children in the junction table
     DELETE FROM AuthorTitles WHERE BOOK_TITLE_ID = @Book_ID
    
     -- Now, remove the parent record on BookTitles
     DELETE FROM BookTitles WHERE ID = @Book_ID
    
    go
    

    In general, you want to resist the temptation to do Table Maintenance and other things like this in Triggers. As triggers are invisible, add additional overhead, can cause maintenance problems for the DBA’s, and can lead to many subtle transactional/locking complexities and performance issues. Triggers should be reserved for simple things that really should be hidden from the client application (like auditing) and that cannot be practically implemented in some other way. This is not one of those cases.

    If you really want an “invisible” way of doing this then just implement a Cascading Foreign-Key. I do not recommend this either, but it is still preferable to a trigger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you show a coding example that has the Using statement with a scalar
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't
can anyone recommend a website crawler that can show me all of the links
It seems that we can show layers and even use a different zPosition for
I know that you can show current GPS moving location on map with WP7
Can you show sample code for reading a drive label or volume name in
if so can show simple example, ex in jquery ajax.post
Can anyone show a short and simple code snippet? It should take the name
My doubt is simple, how can I show an exception using this INotifyDataErrorInfo in
How I can show only 2 posts on my websites first page? I am

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.