Nov 11, 2013

How to get the all the columns name of a given table in sql server?

In sql server information about all the columns and its properties of a table is stored in the system view sys.Columns.

Suppose we have created a table in sql server by following query:

CREATE TABLE Student(
    Roll_No BIGINT IDENTITY,
    Stu_Name VARCHAR(100),
    DOB DATETIME,
    IsActive BIT
)

Sql query to get the all the columns name of table Student

SELECT name
FROM Sys.columns
WHERE object_id = OBJECT_ID('Student')

Output:
name
Roll_No
Stu_Name
DOB
IsActive

No comments:

Post a Comment