April 20, 2008 at 11:25 pm
Hi,
I want to check the columns that are present in one particular table.
What is the T-Sql command to check the columns for a table.
April 21, 2008 at 1:32 am
Check what?
Existence of columns? data? integrity? statistics? relations? or...?
April 21, 2008 at 3:38 am
If you just want a list of column names you can use FMTONLY
SET FMTONLY ON;
GO
SELECT *
FROM MyTable
go
SET FMTONLY OFF;
[font="Verdana"]Markus Bohse[/font]
April 21, 2008 at 3:45 am
Another way...
SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'MyTable'
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 21, 2008 at 4:48 am
The OP wrote a vague question. If he/she doesn't take the effort to clear doubts, why do you keep guessing?
April 21, 2008 at 4:52 am
Robert (4/21/2008)
The OP wrote a vague question. If he/she doesn't take the effort to clear doubts, why do you keep guessing?
I'm guessing that wasn't the right side of bed that you climbed out of this morning! 😛
--------
[font="Tahoma"]I love deadlines. I like the whooshing sound they make as they fly by. -Douglas Adams[/font]
April 21, 2008 at 4:55 am
Robert (4/21/2008)
The OP wrote a vague question. If he/she doesn't take the effort to clear doubts, why do you keep guessing?
Hi Robert
There are a few reasons. Some people find it difficult to describe what they want, and giving them something can help draw it out of them. Also, the suggestion might be useful for others who stumble on this thread.
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 21, 2008 at 5:32 am
Hi Robert,
Sorry! My question is want to check the column names for a single table.
I got the answer for my question.
The answer is sp_columns 'table name'
Thanks for your advice.
April 21, 2008 at 11:26 am
You can also use this:
select
name
from sys.columns
where object_id =object_id('my_table')
and name ='my_column'
April 22, 2008 at 1:22 am
Its fun to see all the different methods about retrieving the information.
😀
April 22, 2008 at 4:55 am
Or this
SELECT c.[NAME]
FROM sysColumns c
INNER JOIN sysObjects o
ON c.[ID] =o.[ID]
WHERE o.[NAME] = 'tblName'
April 22, 2008 at 5:37 am
or this
exec sp_help tablename
......next
---------------------------------------------------------------------
April 22, 2008 at 7:25 am
Since we're discussing the various methods, here's a related excerpt from BOL:
The core of the SQL Server 2005 system catalogs is a set of views that show metadata that describes the objects in an instance of SQL Server. Metadata is data that describes the attributes of objects in a system. SQL Server-based applications can access the information in the system catalogs by using the following:
* Catalog views. We recommended this access method.
* Information schema views.
* OLE DB schema rowsets.
* ODBC catalog functions.
* System stored procedures and functions.
We recommend using catalog views to access metadata for the following reasons:
* All metadata is made available as catalog views.
* Catalog views present metadata in a format that is independent of any catalog table implementation, therefore catalog views are not affected by changes in the underlying catalog tables.
* Catalog views are the most efficient way to access core server metadata.
* Catalog views are the general interface to catalog metadata and provide the most direct way to obtain, transform, and present customized forms of this metadata.
* Catalog view names and the names of their columns are descriptive. Query results match what might be expected by a user who has a moderate knowledge of the feature that corresponds to the metadata that is being queried.
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply