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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:45:06+00:00 2026-05-14T06:45:06+00:00

Please help me to write a trigger that adds new rows to a table.

  • 0

Please help me to write a trigger that adds new rows to a table.

I have 3 tables in my database:

  1. Regions (id, name); id – primary;
  2. Technics (id, name); id – primary;
  3. Availability (id, region, technic, count); id – primary, region – foreign on Regions.id, Technik – foreign on technics.id.

I want to add new row in Availability for each Technics row on adding row in Regions.

Somethink like:

procedure void OnAddNewRegion(int region)
{
    foreach (Row r in Technic)
    {
        Availability.Rows.Add(new Row(id, region, r.Id, 0));
    }
}

But in a SQL trigger.
I want to do the same on adding new Technics row.

  • 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-14T06:45:07+00:00Added an answer on May 14, 2026 at 6:45 am

    try something like this (assuming Availability.id is an identity), which will also handle multiple rows being inserted at one time:

    CREATE TRIGGER TR_Regions ON Regions 
    FOR INSERT
    AS
    INSERT INTO Availability 
            (region, technic, count)
        SELECT
            i.id, t.id, 0
            FROM INSERTED            i
                CROSS JOIN Technics  t
    
    GO
    

    you don’t say how Regions joins with Technics, so I cross joined them (every inserted Regions, gets one row for every Technics).

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

Sidebar

Related Questions

Please help me to write the following sql. I have a table like this,
Could anybody please help me to write rewriterule, that redirects http<->https (back and force
I am a new with T-SQL. So, please help me to write the sql.
I need to write a trigger that will create a record in another table.
Please help me to write this code i want to display table like this
java experts can you please help me write detached queries as a part of
Can you please help me to write a sed command to remove the price
Please help me to write an SQL query with the condition as NOT LIKE
I need help to write a MySQL query that would do the following for
Please help me to write Regular expression on C# for getting Int64 value from

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.