How do I return the SQL data types from my query?

前端 未结 13 1679
耶瑟儿~
耶瑟儿~ 2021-01-29 23:58

I\'ve a SQL query that queries an enormous (as in, hundreds of views/tables with hard-to-read names like CMM-CPP-FAP-ADD) database that I don\'t need nor want to understand. Th

13条回答
  •  不要未来只要你来
    2021-01-30 00:33

    You could also insert the results (or top 10 results) into a temp table and get the columns from the temp table (as long as the column names are all different).

    SELECT TOP 10 *
    INTO #TempTable
    FROM 
    

    Then use:

    EXEC tempdb.dbo.sp_help N'#TempTable';
    

    or

    SELECT * 
    FROM tempdb.sys.columns 
    WHERE [object_id] = OBJECT_ID(N'tempdb..#TempTable');
    

    Extrapolated from Aaron's answer here.

提交回复
热议问题