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.
generate script for table schema and data
Is it possible for tsql to generate the script for specific table schema and data without manually going through the process in SSMS?
1 additional answer
Sort by: Most helpful
-
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.
....
"