Share via

create table script for existing table

JOSHI, Vivek 0 Reputation points
2026-02-08T23:04:04.48+00:00

I want to create a create table script for existing table with indexes

SQL Server Database Engine
0 comments No comments
{count} votes

Answer recommended by moderator
  1. Erland Sommarskog 133K Reputation points MVP Volunteer Moderator
    2026-02-09T22:39:59.52+00:00

    You can also go to Tools->Options and SQL Server Object Explorer->Scripting->Table and View options to select that indexes should be scripted.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. JOSHI, Vivek 0 Reputation points
    2026-02-09T00:17:38.0233333+00:00

    Just right click and Generate Script does not give index details. Hence I will always recommend to use Wizard option - use Task -> Generate Script -> Advanced -> set Index options, triggers to true and then generate the script. The generated script will be the one to be used to create an identical Table or any object as per the source database.


  2. Q&A Assist
    2026-02-08T23:04:10.5566667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To create a CREATE TABLE script for an existing table in SQL Server, you can use SQL Server Management Studio (SSMS) to generate the script. Here are the steps:

    1. Open SQL Server Management Studio and connect to your database.
    2. In Object Explorer, locate the table for which you want to generate the script.
    3. Right-click on the table and select Script Table as > CREATE To > New Query Editor Window. This will generate the CREATE TABLE script for the selected table, including its structure and indexes.

    This method allows you to easily obtain the complete definition of the table, including any indexes that are associated with it.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.