MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 19th, 2010, 08:20 AM
SpiritedAway SpiritedAway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 55 SpiritedAway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 33 m 24 sec
Reputation Power: 5
Check if table is a view

Hi people,

Is there a way for me to query the db to see if a table is a view..?

Thanks

Reply With Quote
  #2  
Old January 19th, 2010, 10:06 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 29 m 14 sec
Reputation Power: 4140
have a look at the INFORMATION_SCHEMA
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old January 19th, 2010, 10:18 AM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,685 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 44 m 49 sec
Reputation Power: 284
Quote:
Originally Posted by SpiritedAway
Is there a way for me to query the db to see if a table is a view..?
A table can never be a view (because it's a table)
(Sorry, could not resist)

But if you want to know if a name refers to a table or a view then follow r937's advice.

Reply With Quote
  #4  
Old January 20th, 2010, 12:19 AM
SpiritedAway SpiritedAway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 55 SpiritedAway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 33 m 24 sec
Reputation Power: 5
Tx for your time chaps - looking into it now...

@shammat
1st time working with views so good to know the proper way of referring to them

Reply With Quote
  #5  
Old January 20th, 2010, 02:34 AM
Devart Team's Avatar
Devart Team Devart Team is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 225 Devart Team User rank is Sergeant (500 - 2000 Reputation Level)Devart Team User rank is Sergeant (500 - 2000 Reputation Level)Devart Team User rank is Sergeant (500 - 2000 Reputation Level)Devart Team User rank is Sergeant (500 - 2000 Reputation Level)Devart Team User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 3 h 17 m 27 sec
Reputation Power: 10
To get list of tables and view you can use select from information_schema.tables -

Code:
SELECT * FROM information_schema.tables;

This system table contans all tables and all views; this table has 'TABLE_TYPE' field, you could use it to define type of object -

For example -

Code:
SELECT * FROM information_schema.tables WHERE 'TABLE_TYPE' = 'BASE TABLE'; -- Gets all tables

SELECT * FROM information_schema.tables WHERE 'TABLE_TYPE' = 'VIEW'; -- Gets all views, without information_schema system views


And there is information_schema.views system table, it contains all views.

Last edited by r937 : January 20th, 2010 at 07:19 AM.

Reply With Quote
  #6  
Old October 5th, 2012, 05:16 AM
shabarinath shabarinath is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 shabarinath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 48 sec
Reputation Power: 0
This may help you

select table_name from information_schema.views;

Reply With Quote
  #7  
Old October 5th, 2012, 05:48 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
For myself, I always prefix views with 'v_'. I never prefix tables (with, for instance, 'tbl_' or 't_') on the assumption that everything is a table unless otherwise stated.

Reply With Quote
  #8  
Old October 5th, 2012, 06:07 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 29 m 14 sec
Reputation Power: 4140
Quote:
Originally Posted by shabarinath
select table_name from information_schema.views;
that will not help

did you even read this (dormant) thread before making that reply?

Reply With Quote
  #9  
Old October 5th, 2012, 06:35 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
>did you even read this (dormant) thread before making that reply?

Oh, darn it! I fell for it again!

Reply With Quote
  #10  
Old October 5th, 2012, 07:18 AM
shabarinath shabarinath is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 shabarinath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 48 sec
Reputation Power: 0
Quote:
Originally Posted by r937
that will not help

did you even read this (dormant) thread before making that reply?


Why man he needs all the indexes list naa

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Check if table is a view

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap