generate script for table schema and data

Thirston Third 21 Reputation points
2022-04-05T12:07:06.4+00:00

Is it possible for tsql to generate the script for specific table schema and data without manually going through the process in SSMS?

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
{count} votes

Accepted answer
  1. Naomi 7,366 Reputation points
    2022-04-05T15:43:34.503+00:00

    It is possible based on meta data views, but may be tricky to do in T-SQL. I would probably start from INFORMATION_SCHEMA.Columns. Tools like Red-Gate SQLPrompt do that.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jingyang Li 5,891 Reputation points
    2022-04-05T21:45:08.577+00:00

    Have you heard this extention .bacpac file?

    You can export your database as a .bacpac(data and schema) file from SSMS.

    Right click on your database name>>Tasks>>Export Data-Tier Application (.bacpac file) This file has all your data and schema.

    You can import this file as new database if you want to.

    "Using the Import Data-tier Application Wizard
    To launch the wizard, use the following steps:

    Connect to the instance of SQL Server, whether on-premises or in SQL Database.

    In Object Explorer, right-click on Databases, and then select the Import Data-tier Application menu item to launch the wizard.
    ....
    "

    0 comments No comments