Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this to get table's column name. But I want to restrict it. It showing me all column name i dont want to show all column name. How to restrict it?
SELECT column_name FROM information_schema.columns WHERE table_name = 'Hadiths_old'
Posted
Updated 26-Oct-13 7:27am
v3
Comments
tgrt 26-Oct-13 13:40pm    
Tables usually have more than one column. Your query is asking for the column names for a specific table. So the question is, what column do you want?

You may have to eclude the names you don't want.
You can do that by providing your WHERE clause some more conditions, like
SQL
WHERE table_name='Hadiths_old'
 AND column_name<>'Idontlikethisone%'
 AND column_name<>'neitherthatone%'

for example.
 
Share this answer
 
if you want to restrict columns suppose you want to see top 3 columns then

SQL
SELECT top 3 column_name FROM information_schema.columns WHERE table_name = 'Hadiths_old'


if you want to see columns which name start abc charecters

SQL
SELECT  column_name FROM information_schema.columns WHERE table_name='Hadiths_old' and column_name like 'abc%';


if you want to see columns which name contains abc word

SQL
SELECT  column_name FROM information_schema.columns WHERE table_name ='Hadiths_old' and column_name like '%abc%';
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900