Using system table: columns : columns « System « SQL Server / T-SQL






Using system table: columns



USE Northwind
GO
1>
2> DECLARE @TBLName nvarchar(128)
3> SET @TBLName = N'Shippers'
4>
5> SELECT name, object_id FROM sys.tables WHERE name = @TBLName
6>
7> SELECT name, column_id, object_id
8> FROM sys.columns
9> WHERE object_id IN
10>     (SELECT object_id
11>     FROM sys.tables
12>     WHERE name = @TBLName)
13>
14> GO

           
       








Related examples in the same category

1.table syscolumns appears in the master database and in every user-defined database.