Pages

Google Analytics Alternative

Search This Blog

Friday, December 16, 2011

How to find a table when you don't know which database it belongs to?

In this very short tip I'd like to share my solution to a yesterday quesiton in MSDN forum - how to find the database the table belongs to. I use my favorite idea of dynamically constructing a query using INFORMATION_SCHEMA.TABLES view.

DECLARE @table sysname, @SQL NVARCHAR(MAX)

SET @table = 'Items'

SET @SQL = ''

SELECT @SQL = @SQL + ';

IF EXISTS (SELECT 1 from ' + QUOTENAME(name) + '.INFORMATION_SCHEMA.Tables WHERE Table_Name = @table

AND TABLE_TYPE = ''BASE TABLE'')

PRINT ''Table ' + @table + ' found in ' + name + ''''

FROM sys.databases

 
EXECUTE sp_executeSQL @SQL, N'@table sysname', @table
That's all. Try it with the table which you may have in multiple databases. I used a bit undocumented way of concatenating multiple rows in a string, so I can not actually use ORDER BY in this code. To be strict, I need to use XML PATH('') approach here instead.

Thursday, December 1, 2011

15 GREAT THOUGHTS BY CHANAKYA



1) "Learn from the mistakes of others... you can't live long enough to make them all yourselves!!"
- Chanakya

2)"A person should not be too honest. Straight trees are cut first and Honest people are screwed first."
- Chanakya

3)"Even if a snake is not poisonous, it should pretend to be venomous."
Chanakya

4)"There is some self-interest behind every friendship. There is no friendship without self-interests. This is a bitter truth."
- Chanakya
                                                            
5)" Before you start some work, always ask yourself three questions - Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead."
- Chanakya

6)"As soon as the fear approaches near, attack and destroy it."
- Chanakya

7)"The world's biggest power is the youth and beauty of a woman."
- Chanakya

8)"Once you start a working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest."
- Chanakya

9)"The fragrance of flowers spreads only in the direction of the wind. But the goodness of a person spreads in all direction."
- Chanakya

10)"God is not present in idols. Your feelings are your god. The soul is your temple."
- Chanakya

11) "A man is great by deeds, not by birth."
- Chanakya

12) "Never make friends with people who are above or below you in status. Such friendships will never give you any happiness."
- Chanakya

13) "Treat your kid like a darling for the first five years. For the next five years, scold them. By the time they turn sixteen, treat them like a friend. Your grown up children are your best friends."
- Chanakya

14) "Books are as useful to a stupid person as a mirror is useful to a blind person."
- Chanakya

15) "Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth."
-Chanakya