Solved

How can I find all Bit type columns in my database

Posted on 2011-09-27
8
258 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 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