Solved

How can I find all Bit type columns in my database

Posted on 2011-09-27
8
252 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
  • 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
 
LVL 1

Author Comment

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

Invalid object name 'information_schema.Tables'

0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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 59

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 59

Accepted Solution

by:
Kevin Cross earned 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now