I need to recreate the table structure of a SQL server database, but I only have SELECT-access through a textbox in some esoteric software running on a locked-down VM somewhere far away. Through this textbox I can query pretty much anything, but I don't have something like a connection string or command line.
What would be the easiest way to recreate the table structure on a local database?
My guess would be to use system catalog views like sys.all_objects and sys.all_columns, but I don't see an easy way to convert this data to CREATE TABLE-statements. Is there a straightforward way to accomplish this, or am I condemned to writing an error-prone 'conversion script' myself?
SELECTonly access you likely don't have access to be able to view the definition of the objects. As such you might have to use sys.dm_exec_describe_first_result_set (Transact-SQL) and pass it aSELECT *statement against the table; that'll give you the column and their data types which you'll be able to build your own DDL statement from. Of course, you won't have any details ofCONSTRAINTs,TRIGGERS,KEYs, etc.CONSTRAINTSs), and if they are queryingVIEWs then being able toSELECTfrom saidVIEWdoesn't allow you to see its definition.varchar(10)anddecimal(10,2).