When I right-click a table in Object Explorer and click "Script Table" I can get SSMS to script my table.
Can I do that with T-SQL code?
I'm after the "CREATE TABLE xx" code that SSMS generates, so that I can take the script and use on other projects. I need all the bits and pieces, including PRIMARY KEY, CONSTRAINTs, "WITH (PAD_INDEX = " and schema declaration.
I'm on SQL Server 2014
-
Can you please be more specific by what you mean by "T-sql code"?Sir Swears-a-lot– Sir Swears-a-lot2015年04月28日 09:34:25 +00:00Commented Apr 28, 2015 at 9:34
1 Answer 1
From 2012 onwards this is possible and can be done with help OF sys.dm_exec_describe_first_result_set
DMV.
This dynamic management function takes a Transact-SQL statement as a parameter and describes the metadata of the first result set for the statement
You can refer here for a read on this sys.dm_exec_describe_first_result_set
Also, refer to this post explaining the same. Is there a way to generate table create script in TSQL?
Explore related questions
See similar questions with these tags.