How do I script a Create Table DDL for a View?
Example View:
create view dbo.CustomerTransaction
as
select
cust.CustomerId, -- this is int
cust.CustomerName, -- varchar(25)
tr.PurchaseAmount -- decimal(10,2)
from dbo.Customer cust
inner join dbo.Transaction tr
on cust.CustomerId = tr.TransactionId
Expected Result:
create table dbo.CustomerTransaction
(
CustomerId int,
CustomerName varchar(25),
PurchaseAmount decimal(10,2)
)
Best Answer
Since your question tag says SQL Server 2016, you could take advantage of sys.dm_exec_describe_first_result_set which became available in SQL Server 2012.