Search this blog

Wednesday, January 21, 2009

Read SQL error log

In SQL Server Database, There is plenty of external storedprocedure is available.

To Read Error Log, we can use xp_readerrorlog, which is a external SP.

see the following code, it let us know, how to use this SP

This extended stored procedure will return a errorlog file.

EXEC master..xp_readerrorlog

Tuesday, January 20, 2009

SQL: ANY

This following Query Explain, how to use ANY in SQL Query.

USE pubs

GO

SELECT au_lname, au_fname

FROM authors WHERE city = ANY (SELECT city FROM publishers)

GO

EXISTS Function From SQL

This following Query Explains, How to use Exists in SQL Query.

Have a look at the sample given below

USE pubs

GO

SELECT au_lname, au_fname FROM authors

WHERE exists

(SELECT * FROM publishers WHERE authors.city = publishers.city)

GO

When a subquery is introduced with the keyword EXISTS, it functions as an existence test. The WHERE clause of the outer query tests for the existence of rows returned by the subquery. The subquery does not actually produce any data; it returns a value of TRUE or FALSE.

Monday, January 19, 2009

List all SQL Tables and its record count

This code sample shows how to list all Tables and its data Rows count

SELECT

o.name TableName ,

i.rows TblRowCount

FROM

sysobjects o INNER JOIN sysindexes i ON (o.id = i.id)

WHERE

o.xtype = 'u' AND i.indid < 2