473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Finding a Column in Database Table

Hi Every one,

I want to find whether a particular column in a SQL database table exists or not which the "column name".

Kindly help me with the appropriate.

Thanks in Advance.

Regards
Pavankumar P
Dec 19 '07 #1
2 1054
Torgg
41
Since you did not state what language you were using I'll skip the code samples. I found this link and it gives you a SELECT statement that returns all the column names. I would use the SELECT statement to populate a datatable and then I would search the datatable for the Column Name you want. You could also modify the query to select only the column name and table you are looking for, if it returns nothing then the column was not found.

http://www.thescripts.com/forum/thread271784.html

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. COLUMN_NAME,
  3. DATA_TYPE,
  4. CHARACTER_MAXIMUM_LENGTH
  5. FROM INFORMATION_SCHEMA.COLUMNS
  6. WHERE TABLE_NAME = 'Customers'
OR

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. COLUMN_NAME
  3. FROM INFORMATION_SCHEMA.COLUMNS
  4. WHERE COLUMN_NAME = 'YourColumnName' AND TABLE_NAME = 'Customers'

I hope this was helpfull,
Torgg
Dec 19 '07 #2
r035198x
13,262 8TB
Since you did not state what language you were using I'll skip the code samples. I found this link and it gives you a SELECT statement that returns all the column names. I would use the SELECT statement to populate a datatable and then I would search the datatable for the Column Name you want. You could also modify the query to select only the column name and table you are looking for, if it returns nothing then the column was not found.

http://www.thescripts.com/forum/thread271784.html

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. COLUMN_NAME,
  3. DATA_TYPE,
  4. CHARACTER_MAXIMUM_LENGTH
  5. FROM INFORMATION_SCHEMA.COLUMNS
  6. WHERE TABLE_NAME = 'Customers'
OR

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. COLUMN_NAME
  3. FROM INFORMATION_SCHEMA.COLUMNS
  4. WHERE COLUMN_NAME = 'YourColumnName' AND TABLE_NAME = 'Customers'

I hope this was helpfull,
Torgg
That would work for the MySQL database. It would also help if the OP specified which database they were using.
Dec 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rnewman | last post by:
I have a task to where I need to move a column from one table to another. I want to be sure I update any view, stored procedure, trigger, etc. that references the column. I simply want a query that...
4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
2
by: Devesh Aggarwal | last post by:
Hi, I have a backup and restore module in my project. The backup uses a typed dataset object (XSD) to get the data from database and creates a xml file as the backup file (using the WriteXml...
5
by: Chad | last post by:
Could any suggest to me a good way to programmatically identify which SPs update a database column. I would like to create a cross reference for our database.
2
by: TadPole | last post by:
Hi all, My main problems are::::::::: 1. Set a value within a block container that can be used and changed by subsequent templates/block-containers/tables etc.. 2. get/determine/find the...
6
by: Maxi | last post by:
I have 100 tabes in an Access database, every table has 1 filed with 100 names (records), no primary key assigned. I would like to find duplicates. Here is the criteria: The computer should...
10
by: Dixie | last post by:
I need to delete some relationships in code. How do I know what the names of those relationships are?
13
by: pb648174 | last post by:
Whenever I want help on a query, I get told my design is wrong, So this time I'm posting a message during the design phase: How am I going to perfectly design the following? We want to be able...
3
by: DavidB | last post by:
New to .net....sorry if this seems repetitive I have a dataset ordered by date (SQLDataAdapter SelectCommand uses Order By) and want to find a record by a UniqueID(Identity Column). Then I want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.