A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.
1 of 2

SQL Create Script DDL Table from View

How do I script a Create Table DDL for a View?

Example View:

create view dbo.CustomerTransaction
   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)