July 15, 2013 at 10:21 am
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.
July 15, 2013 at 10:38 am
July 15, 2013 at 10:42 am
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 15, 2013 at 10:57 am
That sure helps.
Thank you.
July 15, 2013 at 11:49 am
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.
July 15, 2013 at 7:19 pm
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 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?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
July 15, 2013 at 8:11 pm
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!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply