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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:52:56+00:00 2026-06-13T12:52:56+00:00

I would like to use smo and powershell script to out a trigger that

  • 0

I would like to use smo and powershell script to out a trigger that is attached to a table .

I have found a way to script out the table with the trigger but this is not what,I also wont always know the name of the table the trigger is connected to ,I would just know the trigger name .

I want to give the script the name of the trigger and have it script it out.

I have been looking for a way to do this and have had no luck.

Thanks for your help as always.

  • 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-13T12:52:57+00:00Added an answer on June 13, 2026 at 12:52 pm

    Here’s an example using sqlps:

    SQLSERVER:\SQL\Z001\SQL1\Databases\pubs>$db = get-item .
    SQLSERVER:\SQL\Z001\SQL1\Databases\pubs>$db.Tables | foreach {$_.Triggers} | where {$_.name -like"employee*"} | foreach {$_.Script()}
    
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    
    CREATE TRIGGER employee_insupd
    ON employee
    FOR insert, UPDATE
    AS
    --Get the range of level for this job type from the jobs table.
    declare @min_lvl tinyint,
       @max_lvl tinyint,
       @emp_lvl tinyint,
       @job_id smallint
    select @min_lvl = min_lvl,
       @max_lvl = max_lvl,
       @emp_lvl = i.job_lvl,
       @job_id = i.job_id
    from employee e, jobs j, inserted i
    where e.emp_id = i.emp_id AND i.job_id = j.job_id
    IF (@job_id = 1) and (@emp_lvl <> 10)
    begin
       raiserror ('Job id 1 expects the default level of 10.',16,1)
       ROLLBACK TRANSACTION
    end
    ELSE
    IF NOT (@emp_lvl BETWEEN @min_lvl AND @max_lvl)
    begin
       raiserror ('The level for job_id:%d should be between %d and %d.',
          16, 1, @job_id, @min_lvl, @max_lvl)
       ROLLBACK TRANSACTION
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have some large strings that I would like use as test data
I have for example: $('#field').click(function(){ alert('One'); alert('Two'); }) and i would like use trigger:
I have an array of Integers in Java, I would like use only a
I would like to use R to extract the speaker out of scripts formatted
I would like to use the logout function from Django but not sure how
I would like to use the jenkins script console some more. Where do I
I would like to use the MFMailComposeViewController mailComposeDelegate property with completion block syntax, but
I would like use a panel whose children have coordinates specified as percentage of
I would like use argparse to parse the arguments that it knows and then
i would like use a variable session ($_session) but it doesn't work in Drupal

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.