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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:49:07+00:00 2026-06-02T11:49:07+00:00

I am creating a trigger on a table in a SQL Server database. But

  • 0

I am creating a trigger on a table in a SQL Server database.

But what I am unable to do is this: I have variables @pageid and @templateid populated, and I need to read all template column id’s from one table – basically get a list of them (they depend on the template id and can vary in number) so I need some way of making an array or something and go through it and add it to a table.

So…

  1. how do I read all template id’s (image below: from 1st table (available template fields) – where availabletemplateid is @templateid) into an array?

  2. how do I loop through this array and add them one by one it to another table (image below: 2nd table – (public page to field mapping) with publicpageid = @pageid and fieldid is one by one from the previous step, and field content is “-“)

enter image description here

So far I have

ALTER TRIGGER CreatePageFields
ON dbo.PublicPages
FOR INSERT
AS
BEGIN TRANSACTION

/* variables */
DECLARE
    @pageid bigint,
    @templateid bigint

/* insert template fields for this page */
SELECT @pageid = id, @templateid = templateid FROM inserted

/* TODO 1 get all template field id's */
/* TODO 2 insert each templatefieldid / page combination */    

/* execute */
COMMIT TRANSACTION

GO

Thanks a lot

  • 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-02T11:49:09+00:00Added an answer on June 2, 2026 at 11:49 am

    I don’t think you need an array (table variable) or any looping (cursor). Something like this will be much, much faster (guessing at your table and field names):

    INSERT INTO publicpagetofieldmapping (PublicPageID, FieldID, FieldContent)
    SELECT t1.ID, t2.ID, '-'
    FROM INSERTED t1
    JOIN AvailableTemplateFields t2
    ON t1.TemplateID = t2.availabletemplateid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER
I am creating an After Update Trigger on a SQL Server 2008 table. The
I'm creating a trigger in SQL Server after INSERT, UPDATE and DELETE. Is there
I have a SQL script that acquires table names and creates trigger for those
I need to create a trigger in every database on my sql 2005 instance.
On our live/production database I'm trying to add a trigger to a table, but
I'm creating a trigger for a table, and I have the following statement: UPDATE
I'm having a problem creating a trigger on a database for a project I've
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I exported a database schema from one server using SQL Developer (Tools-> Database Export).

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.