top of page
  • Writer's pictureJagan Mohan Reddy Rajidi

SQL query to display all columns with datatypes for a given Table name

Below query displays all the columns with data types for the given SQL table name. Replace the TableName in below query with your table name.

select[Column Name], case when IN ('char', 'varchar', 'nchar', 'nvarchar') then + ' (' + convert(nvarchar(10),c.max_length ) + ')' when IN ('decimal','numeric') then + ' (' + convert( nvarchar(10),c.precision ) + ', ' + convert( nvarchar(10),c.scale ) + ')' else end [Data Type], case c.is_nullable when 1 then 'Yes' else 'No' end [Allow Nulls] from sys.columns c inner join sys.types t on c.system_type_id=t.system_type_id where object_name(c.object_id)='TableName' order by c.column_id

5 views0 comments

Recent Posts

See All

When you create any new object(table, stored procedure, view,...etc.) in database then same object name will be stored in system table Sysobjects. Following query returns all the object names along wi

Sometimes you get a scenario where you know the column name but don't remember which table it belongs to. Following query will search for a given column name in database schema and returns all objects

bottom of page