Complete definition of a full copy of SQL Server

In the Enterprise version of SQL Server, you can create a create statement for a previously existing table using Script Table As, Create In. This generates a complete create statement for the table, including indexes. Is there a way to do this in T-SQL and therefore be able to copy the table definition into a new table?

+4
source share
2 answers

Nothing simple out of the box in direct T-SQL, which exactly repeats what SSMS does.

However, you can get to this through metadata ( INFORMATION_SCHEMA.COLUMNS , etc.), and I did it quite successfully. Note that indexes are not in INFORMATION_SCHEMA - they are in sys.indexes.

Check out this article , which probably has most of what you want.

+2
source

Create a script in a new query window, then change the database name and run it

+1
source

Source: https://habr.com/ru/post/1334521/


All Articles