How to generate create script of table using SQL query in SQL Server

后端 未结 3 838
心在旅途
心在旅途 2020-12-16 05:54

I want to generate create table script of already created table in my live database.

I know we can generate scripts using right click on table and click on \'script

3条回答
  •  难免孤独
    2020-12-16 06:39

    For a more complete(-ish) solution for generating a CREATE TABLE statement with indexes, triggers and constraints try the stored procedure made by Lowell Izaguirre.

    It has been tested and developed since 2004, last update was in 2013.

    I've also made some improvements to include index options (PAD_INDEX, FILLFACTOR, IGNORE_DUP_KEY):

    here are the changes, can't fit all the code so you'll find the complete modified version at http://pastebin.com/LXpBeuN1 .


    Update

    I've talked with Lowell and a new version will be online soon with the new changes for index options and other improvements.

提交回复
热议问题