Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Calculate tables in a schema Expand / Collapse
Author
Message
Posted Monday, July 15, 2013 10:21 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 3:28 PM
Points: 214, Visits: 626
I need to calculate total # of tables in a particular schema.
Its a user defined table.(Total number of tables seem a lot)


I can view the schema id from
select * from sys.schemas.


Kindly advise.
Post #1473762
Posted Monday, July 15, 2013 10:38 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 11:15 AM
Points: 824, Visits: 2,655
SELECT schema_id, name FROM sys.tables



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Post #1473777
Posted Monday, July 15, 2013 10:42 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 13,067, Visits: 11,903
Of if you want to use the schema name.

select * 
from sys.tables t
join sys.schemas s on t.schema_id = s.schema_id
where s.name = 'YourSchemaName'



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1473780
Posted Monday, July 15, 2013 10:57 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 3:28 PM
Points: 214, Visits: 626
That sure helps.

Thank you.
Post #1473790
Posted Monday, July 15, 2013 11:49 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
Also available under System Views is the INFORMATION_SCHEMA collection which can give you all the information you need for any metadata in the the database.

For listing out your table collection for example:


SELECT * FROM
INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'


This will list every table in the target database.

 
Post #1473816
Posted Monday, July 15, 2013 7:19 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 6:03 PM
Points: 3,609, Visits: 5,221
Steven Willis (7/15/2013)
Also available under System Views is the INFORMATION_SCHEMA collection which can give you all the information you need for any metadata in the the database.

For listing out your table collection for example:


SELECT * FROM
INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'


This will list every table in the target database.

 


Steven - I believe I've heard somewhere that INFORMATION_SCHEMA VIEWs will be deprecated in the future. Too bad because I've found them pretty useful.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1473941
Posted Monday, July 15, 2013 8:11 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
I've heard rumors that the INFORMATION_SCHEMA views are deprecated in later versions, but the information even on MSDN isn't very clear on that. http://msdn.microsoft.com/en-us/library/ms186778.aspx. It seems the INFORMATION_SCHEMA views are still the ANSI-compliant method for querying metadata (if that matters). The link posted does say that some of the views have changed seemingly to be MORE ANSI-compliant than before. From the description at that link it seems mostly the changes involve mandating strict naming conventions. I hope these views don't go away entirely since they have proven very useful to me!

 
Post #1473949
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse