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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:05:21+00:00 2026-05-15T05:05:21+00:00

How do you programmatically generate T-SQL CREATE statements for existing indexes in a database?

  • 0

How do you programmatically generate T-SQL CREATE statements for existing indexes in a database? SQL Studio provides a “Script Index as->Create to” command that generates code in the form:

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = N'IX_myindex')
    CREATE NONCLUSTERED INDEX [IX_myindex] ON [dbo].[mytable] 
    (
        [my_id] ASC
    )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
GO

How would you do this programmatically (ideally through Python)?

  • 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-15T05:05:22+00:00Added an answer on May 15, 2026 at 5:05 am

    Assuming you have 2005 or later, you can simply query sys.indexes for all of the information you need (like they’re doing in the IF NOT EXISTS portion of the query).

    If you’re just looking for all indexes in a database just pull everything from that table within that database. If you’re looking for indexes that meet certain criteria here’s the list of fields in sys.indexes that you can use to filter on. The sys.index_columns table has all of the associated columns for each index as well.

    Using this you should be able to get all the information you need about the indexes in your database.

    This blog post has a pretty good SQL snippet that uses these tricks to interrogate the indexes in the database, and you may be able to use a fair bit of it to do what you want.

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

Sidebar

Related Questions

I'd like to be able to retrieve programmatically the command strings that generate the
My understanding of SQL*Loader's conventional path is that it simply generates INSERT statements and
I'm looking to generate the SQL scripts for table creation programmatically based on class
I need to programmatically generate an RTF document with a table that has a
I have a need to generate SQL queries against a variety of database providers,
Here is what i have: a SQL CE database, that holds this Category table,
I generate all my columns in a subclassed DataGridView programmatically. However Visual Studio 2008
I'm using CR for VS2010 to programmatically generate PDF and Excel documents from Crystal
I'm trying to generate some html programmatically in my code behind for a user
How can I write to/generate a *.doc file programmatically using c or c++? Is

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.