Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sp_columns return no results?

Tags:

sql-server

I'm trying to "describe" a table for a different post I have on StackOverflow, but when I run sp_columns, no results or rows are shown.

sp_columns assignee

Results:

A bunch of column headers...

What's wrong with my database, and why doesn't this work?

like image 510
mlissner Avatar asked Dec 05 '22 12:12

mlissner


2 Answers

Instead of sp_columns use catalog views (many of these sp_ procedures are not updated for new features).

SELECT name, system_type_id, ...
  FROM sys.columns
  WHERE [object_id] = OBJECT_ID('dbo.TableName');
  ---- yes this is important ----^^^^

Also, make sure you're in the right database, obviously.

like image 62
Aaron Bertrand Avatar answered Jan 02 '23 16:01

Aaron Bertrand


For a specific schema, try:

sp_columns tableName, schemaName
like image 41
WEFX Avatar answered Jan 02 '23 15:01

WEFX