?
Solved

How can I find all Bit type columns in my database

Posted on 2011-09-27
8
Medium Priority
?
267 Views
Last Modified: 2012-05-12
I need to find all columns which are of type Bit in my database.

What SQL query would I need to return me that information?  I am using MS SQL Server v2008.
0
Comment
Question by:FrancineTaylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 5

Expert Comment

by:eridanix
ID: 36712431

USE [your_database_name]
SELECT C.TABLE_NAME, C.column_name
FROM sys.Tables T INNER JOIN
	INFORMATION_SCHEMA.COLUMNS C ON T.name = C.TABLE_NAME
WHERE C.DATA_TYPE = 'bit'

Open in new window

0
 
LVL 1

Author Comment

by:FrancineTaylor
ID: 36712443
Threw this error:

Invalid object name 'sys.Tables'
0
 
LVL 5

Expert Comment

by:eridanix
ID: 36712481
So try this:
USE [your_database_name]
SELECT C.TABLE_NAME, C.column_name
FROM information_schema.Tables T INNER JOIN
	INFORMATION_SCHEMA.COLUMNS C ON T.TABLE_NAME = C.TABLE_NAME
WHERE C.DATA_TYPE = 'bit'

Open in new window

0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 1

Author Comment

by:FrancineTaylor
ID: 36712527
Hmm.  Still not working...

Invalid object name 'information_schema.Tables'

0
 
LVL 5

Expert Comment

by:eridanix
ID: 36712619
This can be problem with your perminiton.
Try to login as administrator if you can.

I have no problem with both this queries.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36712652
Why are you joining to anything? INFORMATION_SCHEMA.COLUMNS has the information, right?
SELECT C.TABLE_NAME, C.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS C
WHERE C.DATA_TYPE = 'bit'

Open in new window

0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36712685
@eridanix: remember, not everyone's database is case insensitive. INFORMATION_SCHEMA views are all uppercase. sys.* is all lowercase. I would not mix the two anyway. For newer versions of SQL, use the INFORMATION_SCHEMA views. Therefore, if you need TABLES, then it is like this:
SELECT C.TABLE_SCHEMA, C.TABLE_NAME, C.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS C
JOIN INFORMATION_SCHEMA.TABLES T 
   ON T.TABLE_SCHEMA = C.TABLE_SCHEMA
   AND T.TABLE_NAME = C.TABLE_NAME
WHERE C.DATA_TYPE = 'bit'
AND T.TABLE_TYPE = 'BASE TABLE'
;

Open in new window

0
 
LVL 5

Expert Comment

by:eridanix
ID: 36712735
@mwvisa1: Thanks for info, you are right. In my projects I use the right case format. But I'am also accustomed, that most of databases I used in past was case insensitive.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question