|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
whether a column exists in my table?(Urgent)
Hi
Can anybody tell me how can I find whether a column exists in my table or not??? Piyush ![]() Last edited by piyush1201 : February 4th, 2004 at 01:18 PM. |
|
#3
|
|||
|
|||
|
Thats fine,now what when it is not so urgent but required?????
|
|
#4
|
||||
|
||||
|
sorry, please clarify your question
to determine whether a particular column exists in the table, run my query, and look at the output |
|
#5
|
||||
|
||||
|
Do you mean programmatically checking MsSQL's system tables to see what columns make a table?
|
|
#6
|
||||
|
||||
|
programmatically, should not the result row be structured using the names of the columns?
that will not give details like datatype, length, precision, nulls, defaults, or keys but the original requirement was "exists" so scanning the column names of a one-row query should do it, no? |
|
#7
|
||||
|
||||
|
Yes, scanning columns names works, mine was just an hypothesis.
|
|
#8
|
|||
|
|||
|
What I was looking for was a front end query that cud give me whether a particular column exists or not , may be a boolean return,surely i am not looking for as detailed info as sp_help table returns.
|
|
#9
|
||||
|
||||
|
in that case, use INFORMATION_SCHEMA.COLUMNS
this is the best way the only reason i said to use TOP 1 was because (a) you did not mention that you wanted a programmatic solution, and (b) you said it was urgent now, since it has become clear that your problem is programmatic and is not urgent, i would recommend the correct way |
|
#10
|
|||
|
|||
|
How about the following
SELECT COUNT(*) FROM SYSCOLUMNS WHERE ID = OBJECT_ID('TableName') AND Name = 'ColumnName' If you get a count of > 0 then your column exists. |
|
#11
|
||||
|
||||
|
Information schema views are better because "These components constitute a published API for obtaining system information from SQL Server. Microsoft maintains the compatibility of these components from release to release. The format of the system tables is dependent upon the internal architecture of SQL Server and may change from release to release." (see System Tables)
|
|
#12
|
|||
|
|||
|
Excuse me.
I can to find all the table which have a ColumName known ? Something as: SELECT TableName FROM ??? WHERE COLUMN_NAME = 'ColumnName' I want to know all the tables which contains a column with name = 'CITY' Thanks Quote:
|
|
#13
|
||||
|
||||
|
nicola65mi, have you tried the INFORMATION_SCHEMA views?
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > whether a column exists in my table?(Urgent) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |