Sunday, February 12, 2012

4 ways to know the record count of a table

Please tell me the 4 ways to know the record count of a table?Please tell me the 4 ways to know the record count of a table?I usually print off the contents and then count the number of lines. WARNING - if your table is WIDE you need an A3 printer set to landscape.

1 down 3 to go.
HTH|||select sum(qqq) from
(select someField as fff, count(isnull(someOtherField, 'pootleflumpisafunnyperson')) as qqq from someTable group by someField)

should give a fairly accurate approximation of the actual number.|||use a theta self-join to assign a ranking number to each row, then inner join this result to a table of integers in an UPDATE statement, setting each integer to NULL if there is a match, and finally, select MIN(integer)-1 from the integers

this would be so much easier in oracle, where you don't have to use the ranking join, you can use its builtin ROWNUM|||...or cheat off of somebody else taking the same class you are.|||Count the number of data blocks occupied by the table and divide by the number of whole rows that each block will hold.|||use a theta self-join to assign a ranking number to each row, then inner join this result to a table of integers in an UPDATE statement, setting each integer to NULL if there is a match, and finally, select MIN(integer)-1 from the integers
That's why I love these forums - you've just slashed our toner expenditure Rudy.
Your db forums boycot does't extend to NZDFs then huh? ;)|||Your db forums boycot does't extend to NZDFs then huh? ;)that is correct :)

i am not going to visit regularly, i am no longer going to delete spam, even if you report it, i am no longer going to rename threads to make them easier to search and to prevent others from wasting their time to find out what the brilliantly named "I need help!!!!!!!!!!" thread might be about, and i am not going to open threads that have gone unanswered for a day to see if i can help folks

however, i might still browse these forums if i am extremely bored, which happens too infrequently for my liking, and maybe, if i feel like it, i might offer a reply, like in a "please do my homework for me" or "i can't find my ass with both hands, what does RTFM mean?" thread|||OK, well I'm not taking a test...and I can only think of 2...

SELECT COUNT(*)
sp_spaceused|||come on brett, it's not that hard

here's another way: if the table has an IDENTITY column, determine the initial seed and increment values from the system seed table joined with the system increment table on the database and table names, then SELECT MAX(id) from the table, and using a bit of arithmetic, combine this with the seed and increment values to determine how many rows there would still be if none have been deleted, then run a query on the identity values to count how many are missing (i.e. actually were deleted), subtract this from the number of rows from the first step, and voila, the number of rows that are currently in the table

:)|||come on brett, it's not that hard

here's another way: if the table has an IDENTITY column, determine the initial seed and increment values from the system seed table joined with the system increment table on the database and table names, then SELECT MAX(id) from the table, and using a bit of arithmetic, combine this with the seed and increment values to determine how many rows there would still be if none have been deleted, then run a query on the identity values to count how many are missing (i.e. actually were deleted), subtract this from the number of rows from the first step, and voila, the number of rows that are currently in the table

:)

You can't be serious.....|||You can't be serious.....

I think he forgot the [sarcasm] tags... :D

Regards,

hmscott|||a reply with Non-Zero Deviosity Factor requires no sarcasm tags

:)|||Why is it everyone forgets the obvious one.

Use a packet sniffer, to sniff the results of "select * from table", take the total number of bytes returned, and divide by the rowlength.|||Why is it everyone forgets the obvious one.

Use a packet sniffer, to sniff the results of "select * from table", take the total number of bytes returned, and divide by the rowlength.
Maybe because you have to multiply the number of framing bits by 2e-1 before you can subtract them from the total bits transferred.|||a reply with Non-Zero Deviosity Factor requires no sarcasm tags

:)

The dreaded NZD factor! Next you'll tell me that there's no such thing as Rodents of Unusual Size!

Anybody want a peanut?

Regards,

oh, never mind...

[PS. It's late, I'm sick, I refuse to be held responsible for anything I post.]|||There's always the method that can be derived from the sieve of Eratosthenes:

1) Determine the actual size of the database files (in bytes).
2) Scan the pages at a low level, and decrement the size from step one for each page that is NOT owned by the target table.
3) Traverse the index 0 or 1 pages of the target object, counting valid couplets (tuple pointers). Be sure to ignore any couplets that haven't been reclaimed by the ghost exorcisor.
4) The final count should be the actual traversed row count, which is often the current row count.

-PatP|||Using Eratosthenes Sieve to determine rowcount...a Prime example of SQL Programming. ;)|||Son't forget this little gem of uber-coding:

http://www.thedailywtf.com/forums/30368/ShowPost.aspx|||Son't forget this little gem of uber-coding:

http://www.thedailywtf.com/forums/30368/ShowPost.aspx

I surely qon't|||I surely qon'ttee hee

good one, brett|||Son't forget this little gem of uber-coding:

http://www.thedailywtf.com/forums/30368/ShowPost.aspxthat's hilarious, i don't think i saw that one before, i'm dyin' over here...

:rofl: :rofl:|||I refuse to be slandered...another Brett J. out there...hmmmmm...J is for Joseph, K is for Ketel One, L is for Lagavulin, M is for Margarita...oh never mind

No comments:

Post a Comment