Assume a case when I have count the no of available rows in a table, should we use "Select Count(*) From ", is it an optimized query.Note: I am not aware of the table name and its structure, actually it came from some parameter values. And I want to count its rows through .net code.Please let me know, what should be the most optimized query in this regards.SubrataC999@gmail.com
Welcome to the forum! This thread might be interesting for you: http://sql-server-performance.com/Community/forums/p/32434/167409.aspx
Hi, you can create a proc with table name as an input parametre.CREATE PROCEDURE Usp_GetTableRows @tblName varchar(50)AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;select rows from sys.partitions where object_id=object_id(@tblName)END GO
[quote user="Madhivanan"] or select rows from sysindexes where indid<2 and name=@table_name [/quote] ...where @table_name really is @index_name... []
<P mce_keep="true">[quote user="FrankKalis"] <P>[quote user="Madhivanan"]</P><P>or</P><P>select rows from sysindexes where indid<2 and name=@table_name</P><P>[/quote] </P><P>...where @table_name really is @index_name... <IMG alt=Smile src="http://sql-server-performance.com/Community/emoticons/emotion-1.gif"><BR></P><P>[/quote]</P><P>Yes. Actually I wanted to write this</P><P>select rows from sysindexes where indid<2 and object_name(id)=@table_name</P>
<p>[quote user="Madhivanan"]</p><p>[quote user="FrankKalis"] </p><p>[quote user="Madhivanan"]</p><p>or</p><p>select rows from sysindexes where indid<2 and name=@table_name</p><p>[/quote] </p><p>...where @table_name really is @index_name... <img src="http://sql-server-performance.com/Community/emoticons/emotion-1.gif" alt="Smile"><br></p><p>[/quote]</p><p>Yes. Actually I wanted to write this</p><p>select rows from sysindexes where indid<2 and object_name(id)=@table_name</p><p>[/quote] </p><p>...this is sooo SQL Server 2000.... [] <br></p>