Archive
SQL: Column metadata query
A friend of mine asked a question on how to retrieve SQL column metadata, hence wrote this query with help from stack overflow.
I had to make some adaptations; basically used a nested query to create temporary result set in order to apply a filter on a column alias.
In order to use this query please remember to change value for the Where clause on column alias TableName. For e.g. ‘%MyTableName%’ to filter any TableName containing string ‘MyTableName’. For exact results please remove %% from the where clause. For e.g. ‘MyTableName’.
You can add more columns to this output by choosing columns from output of following query: select * from sys.columns. Then add the column to the nested query along with an appropriate column alias.
Select * from
(Select
object_NAME(Columns.object_id) As TableName,
Columns.name As 'ColumnName',
Types.name As 'Type',
Columns.max_length As 'Length/Size'
from sys.columns Columns INNER JOIN sys.types Types ON Types.system_type_id = Columns.system_type_id)
AllColumnMetaData
Where TableName like '%sysrscols%'
![Output Screenshot](https://nibuthomas.wordpress.com/wp-content/uploads/2021/05/e4688-image.png)
Hope this helps. Good day!
The Old Rugged Cross
![](https://nibuthomas.files.wordpress.com/2010/01/cross.jpg)
Daily Manna
Copyright and Disclaimer
Disclaimer: These postings are provided "AS IS" with no warranties, and confer no rights.
Categories
- .net (24)
- C# (16)
- VB (12)
- WindowsIdentity (1)
- WPF (1)
- ActiveDirectory (1)
- ActiveX (2)
- Announcements (4)
- ATL (5)
- Books (1)
- C Programming (14)
- C++, VC++ (96)
- CodeProject (1)
- COM (20)
- Debugging (31)
- Development Tools (5)
- DevTools (1)
- DOS (2)
- General (14)
- MVP Stuff (1)
- MVP Summit 2008 (5)
- HTML (1)
- Interop (2)
- Interview Questions (4)
- C++ (1)
- MFC (60)
- Microsoft (8)
- Windows 8 (2)
- Windows 8 Apps (1)
- Windows Phone (2)
- Microsoft Office (1)
- My thoughts (3)
- Networking (1)
- Parallel Programming (1)
- Polls (2)
- PowerShell (10)
- Sharepoint (9)
- SQL (1)
- STL (1)
- STL (1)
- STL (1)
- STL (1)
- STL (1)
- Strange bugs (6)
- Uncategorized (2)
- Undocumented WinAPI (6)
- Visual C++ Compiler (5)
- Visual studio (37)
- Visual Studio 2012 (3)
- Visual Studio 2013 (7)
- Win32Controls (1)
- WinDbg (9)
- Windows (24)
- Batch programming (4)
- Explorer (1)
- SysInternals (1)
- Tools (3)
- Windows 10 (1)
- Windows API (191)
- Windows Phone (2)
- WPF (1)
- XML (1)
- XPath (1)