SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


List all tables and their respective information.


List all tables and their respective information.

Author
Message
fercasas
fercasas
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 227
Comments posted to this topic are about the item List all tables and their respective information.

Fernando Casas Osorio
Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90503 Visits: 17958
I prefer mine below


SELECT OBJECT_NAME(i.object_id) AS TableName
, ISNULL(i.name, 'HEAP') AS IndexName
, i.index_id as IndexID
, i.type_desc AS IndexType
, p.partition_number AS PartitionNo
, p.rows AS NumRows
, au.type_desc AS InType
, au.total_pages AS NumPages
, au.total_pages * 8 AS TotKBs
, au.used_pages * 8 AS UsedKBs
, au.data_pages * 8 AS DataKBs
, o.create_date AS CreateDate
, o.modify_date AS ModifyDate

FROM sys.objects o INNER JOIN sys.indexes i
ON o.object_id = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units au ON
CASE
WHEN au.type IN (1,3) THEN p.hobt_id
WHEN au.type = 2 THEN p.partition_id
END = au.container_id
WHERE OBJECT_NAME(i.object_id) <> 'dtproperties'
AND o.is_ms_shipped <> 1
ORDER BY TableName, i.index_id



-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
fercasas
fercasas
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 227
Excellent, your script is much more efficient because it has fewer lines and gives the same results.

Thanks for your input, we are here to help each other. :-)

Fernando Casas Osorio
Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)SSC Guru (90K reputation)

Group: General Forum Members
Points: 90503 Visits: 17958
No problem, mine doesn't give object schema but that would be easy to obtain by joining to the sys.schemas catalog.

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
m.g.faina
m.g.faina
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 5
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'i'.

That's what I get when trying to parse it, 2008 R2.

The initial one parses OK but give in execution

Msg 4104, Level 16, State 1, Line 12
The multi-part identifier "SYS.partitions.INDEX_ID" could not be bound.
Msg 4104, Level 16, State 1, Line 16
The multi-part identifier "SYS.partitions.INDEX_ID" could not be bound.
m.g.faina
m.g.faina
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 5
Got Perry's query to work, nice!
Still not able to get the initial one working.
fercasas
fercasas
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 227
Hello,

The script has been executed in SQL Server 2008 R2 and it works fine, please try this again eliminated the "ORDER BY DESC COUNT_ROWS".

Regards. :-)

Fernando Casas Osorio
m.g.faina
m.g.faina
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 5
same message -
Msg 4104, Level 16, State 1, Line 12
The multi-part identifier "SYS.partitions.INDEX_ID" could not be bound.
Msg 4104, Level 16, State 1, Line 16
The multi-part identifier "SYS.partitions.INDEX_ID" could not be bound.

It is line 16

WHEN SYS.partitions.INDEX_ID < 2 THEN DATA_PAGES ELSE 0 END, 0)) * (SELECT low / 1024 AS VALUE

Not so sure why it could not be bound...
robert.sterbal 56890
robert.sterbal 56890
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3539 Visits: 1284
The link to you blog:

http://recursossqlserver.blogspot.com/

is broken at the moment.

Is there a typo?
Iwas Bornready
Iwas Bornready
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29230 Visits: 885
Perry Whittle (3/14/2013)
No problem, mine doesn't give object schema but that would be easy to obtain by joining to the sys.schemas catalog.
Thanks for the alternate version.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search