Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, March 23, 2012

Number of rows in a table without using count(*)

In a script I would like to have the approximate number
of rows of a table.
Is there an easy way to get the 'approximate' number
of rows in a table without using count(*).
ben brugmanHi,
Use the below query,
select object_name(Id) as table_name,rows from sysindexes where indid=0
Thanks
Hari
MCDBA
"ben brugman" <ben@.niethier.nl> wrote in message
news:#0zv5NkuDHA.1888@.TK2MSFTNGP10.phx.gbl...
> In a script I would like to have the approximate number
> of rows of a table.
> Is there an easy way to get the 'approximate' number
> of rows in a table without using count(*).
> ben brugman
>|||Hari
Why just no use
sp_spaceused 'table'
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:OUBPZWkuDHA.2432@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Use the below query,
> select object_name(Id) as table_name,rows from sysindexes where indid=0
> Thanks
> Hari
> MCDBA
> "ben brugman" <ben@.niethier.nl> wrote in message
> news:#0zv5NkuDHA.1888@.TK2MSFTNGP10.phx.gbl...
> > In a script I would like to have the approximate number
> > of rows of a table.
> >
> > Is there an easy way to get the 'approximate' number
> > of rows in a table without using count(*).
> >
> > ben brugman
> >
> >
>|||approx=not accurate if stat is not uptodate.
select rows
from sysindexes
where id=object_id('your table name')
and indid<2
--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net
"ben brugman" <ben@.niethier.nl> wrote in message
news:%230zv5NkuDHA.1888@.TK2MSFTNGP10.phx.gbl...
> In a script I would like to have the approximate number
> of rows of a table.
> Is there an easy way to get the 'approximate' number
> of rows in a table without using count(*).
> ben brugman
>|||Thanks, Hari, Uri, Oj
this is exactly what I have been looking for.
(I did look at the sysindexes and sysobjects yesterday, but
missed the rows entry in the sysindexes table. Why, I do not know).
(Space_used uses the same numbers but it is more difficult to get
space_used results in a table).
Thanks again,
ben brugman
"ben brugman" <ben@.niethier.nl> wrote in message
news:#0zv5NkuDHA.1888@.TK2MSFTNGP10.phx.gbl...
> In a script I would like to have the approximate number
> of rows of a table.
> Is there an easy way to get the 'approximate' number
> of rows in a table without using count(*).
> ben brugman
>

Monday, February 20, 2012

NULL output when trying to script objects with SQL-DMO

The following statement SHOULD generate a script of the specified stored
procedure. Instead, it returns NULL. Please tell me what I'm doign wrong:
DECLARE @.oServer int
DECLARE @.method varchar(300)
DECLARE @.TSQL varchar(4000)
DECLARE @.ScriptType int
EXEC sp_OACreate 'SQLDMO.SQLServer', @.oServer OUT
EXEC sp_OASetProperty @.oServer, 'loginsecure', 'true'
EXEC sp_OAMethod @.oServer, 'Connect', NULL, 'US1SQLDEV'
SET @.ScriptType = 1|4|32|64|256|262144
SET @.method = 'Databases("Compass").' +
'StoredProcedures("p_rpt_Distance").Script' +
'(' + CAST (@.ScriptType AS VARCHAR) + ')'
EXEC sp_OAMethod @.oServer, @.method ,
@.TSQL OUTPUT
SELECT @.TSQL
EXEC sp_OADestroy @.oServercongratulations, you've found the slowest possible way to do this ;)
if your sql is going to be <=4000 chars, you should just go against
syscomments. otherwise, your variable won't be big enough, anyway.
if you're dead-set on using the object junk, check the script type.
you've got the script type of 64 (To File only) set, but no file name to
output to.
CadeBryant wrote:
> The following statement SHOULD generate a script of the specified stored
> procedure. Instead, it returns NULL. Please tell me what I'm doign wrong
:
> DECLARE @.oServer int
> DECLARE @.method varchar(300)
> DECLARE @.TSQL varchar(4000)
> DECLARE @.ScriptType int
> EXEC sp_OACreate 'SQLDMO.SQLServer', @.oServer OUT
> EXEC sp_OASetProperty @.oServer, 'loginsecure', 'true'
> EXEC sp_OAMethod @.oServer, 'Connect', NULL, 'US1SQLDEV'
> SET @.ScriptType = 1|4|32|64|256|262144
> SET @.method = 'Databases("Compass").' +
> 'StoredProcedures("p_rpt_Distance").Script' +
> '(' + CAST (@.ScriptType AS VARCHAR) + ')'
> EXEC sp_OAMethod @.oServer, @.method ,
> @.TSQL OUTPUT
> SELECT @.TSQL
> EXEC sp_OADestroy @.oServer