RSS Feed

sp_columns

sp_columns

sp_columns is a stored procedure. sp_columns display the columns of a single object, either a table or view, that can be queried in the current environment.

Syntax of sp_columns

sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ]
[ , [ @table_qualifier = ] qualifier ]
[ , [ @column_name = ] column ]
[ , [ @ODBCVer = ] ODBCVer ]

Example 1 of sp_columns

CREATE TABLE P
(
p_id varchar(2)
PRIMARY KEY,
LastName varchar(50),
FirstName varchar(50),
City varchar(50)
)

select * from P

Insert into p values (1, 'Dhall', 'Sachin', 'Delhi')
Insert into p values (2, 'Gupta', 'Pankaj', 'Bangalore')
Insert into p values (3, 'Kumar', 'Sanjeev', 'Chandigarh')

exec sp_columns P
[A complete resultant row is divided into 3 parts because of space constraints]









Example 2 of sp_columns

exec sp_columns P, @column_name= 'LastName'
[A complete resultant row is divided into 3 parts because of space constraints]