Search Blog

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

HOW TO count all rows in each table in a database in MS-SQL

Ever tried running "select count(*)" on a table with millions of rows? Or being asked to find that out for every table in a huge database? I had to count all rows in every table in a database at work today. With quite a few  tables having upwards of 50 million rows, and with 100s of tables in the db, getting all results using the plain vanilla "select count(*) would take all day.

Here is a super efficient SQL query that counts all rows in every table in a database, and FAST. Tested on MS SQL:-

SELECT  [TableName] = so.name,  [RowCount] = MAX(si.rows)  FROM sysobjects so, sysindexes si  WHERE
so.xtype = 'U'  AND si.id = OBJECT_ID(so.name)
GROUP BY  so.name
ORDER BY 2 DESC

HOW TO make a link open in a new browser window

So I started this blog and wrote my first few posts only to find out that all the links in my posts were taking readers away from my post. Did some research and turns out it is fairly simple to make a link open in a new tab or new window when a user clicks on it. Here is what you do:-

Modify
<a href ="http://thedailyhowto.blogspot.com/">Daily HOWTO blog</a>
to
<a target="_blank" href="http://thedailyhowto.blogspot.com/">Daily HOWTO blog</a>

Here are the other values available for the target attribute:-
target="_blank"      Open link in a new tab/ window.
target="_self"         Open link in the same window (default)

target="_parent"     Open link in the parent frame in a multi-frame page.
target="_top"         Open link  in top level window when used in a multi-frame page.

To make all links on your page open in a new window, just add <base target="_blank"> between the <head> and </head> tags in your html.