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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:45:53+00:00 2026-06-05T10:45:53+00:00

I want to get the new table definition(create table statement) and save it to

  • 0

I want to get the new table definition(create table statement) and save it to a txt file when the ddl alter table trigger fires.

I have tried xp_helptext, this only works for view or stored proc. I hope there’s something like this for altering table to get new create statement.

I have also tried use xp_cmdshell to launch a .net. And hard code the script according to the info from INFORMATION_SCHEMA. However, it is locked because the trigger is not closed during the .net is running.

  • 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-05T10:45:56+00:00Added an answer on June 5, 2026 at 10:45 am

    You can’t do this. SQL Server does not generate a new CREATE TABLE statement when you run an ALTER TABLE. You will see that EVENTDATA() in your DDL trigger only contains the ALTER command, not the entire table definition. You will also notice that neither INFORMATION_SCHEMA nor the catalog views like sys.tables ever store a copy of the CREATE TABLE generation, even when the original command was CREATE TABLE, so there is nothing to get from that route.

    You can see what Management Studio does to generate the create table script by running a server-side trace, then right-clicking a table and choosing Script As > Create To > New Query Editor Window. I can assure you this is not some simple SELECT create_table FROM sys.something but rather a set of metadata queries against a slew of DMVs. You don’t even see the CREATE TABLE being assembled because it is done in the code, not from the database or in the query.

    More accessible: SMO has methods for scripting objects such as tables. But I don’t think you should try to do this from within the trigger – bad idea to make the ALTER TABLE transaction wait for your ability to invoke some external process, write to a file system, etc. Here is what I propose: when a table has its definition changed, in the DDL trigger add a row to a queue table. On the OS have a PowerShell script or C# command line executable that uses SMO methods to generate the script given a table name. Schedule that script to run every minute or every 5 minutes, and check the queue table for any new alters that have happened but that you haven’t captured. The program writes the file based on the CREATE TABLE script that SMO generated, then updates the queue table (or removes the row) so that it is only processed once.

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

Sidebar

Related Questions

I create new desktop with CreateDesktop and want to get it's DC & RC.
I would like to create user in my user table when new user have
I want to add days to a date to get a new date in
I am new to iPhone programming. I want to get the height and width
i am new to asp.net, ı want to get data from url on asp.net.
I want get the time used for a case so I can create an
I want to get the new created ID when you insert a new record
I want to get the latest raw job history and save them in my
I have a table (SQL 2000) with over 10,000,000 records. Records get added at
I have a table of forum posts, and want to improve the basic search

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.