Good morning,
Suppose I have two databases, A and B, hosted on the same ASE server. While connected to database A, I need to retrieve the value of rowcnt(doampg) for a table in database B.
For example, I have tried the following query:
SELECT rowcnt(doampg)
FROM B..sysindexes
WHERE id = object_id("B..table_name")
AND indid = 0
However, the result is always 0 when I execute this query from database A. If I switch my current database context to B and execute the equivalent query there, I get the expected information.
Is there a way to retrieve the correct value for a table in database B while remaining in database A, without having to switch the current database context? More specifically, is there an alternative approach that does not require querying systabstats after executing flushstats?
I'm having this problem in ASE 12.5.x, but in later versions, "rowcnt" no longer exists and "row_count" is used instead; perhaps my problem was one of the reasons for the change.
Thank you very much for your time and help. This is an important issue for me, so any technical explanation, documentation references, or suggestions for further testing would be extremely valuable.
Regards and thanks in advanced
Request clarification before answering.
Since the rowcnt() function was deprecated with the introduction of ASE 15.0 I'm going to assume OP is running ASE 12.x in which case I'd suggest a global stored procedure (defined in the sybsystemprocs database with a name that starts with 'sp_' - though I'd suggest 'sp__' to distinguish from system stored procedures).
---------------------
For demo purposes I've created MyObject (table in db1; procedure in db2) :
use db1
go
create table MyObject
(a int null
,b int null
)
go
use db2
go
create procedure MyObject
as
print 'hi'
goRunning the following query in both databases to obtain details on MyObject :
select db_name() as 'database',name as 'object name',id,type
from sysobjects
where id = object_id('MyObject')
go
-- results reformatted for readability
database object name id type
-------- ----------- ---------- ----
db1 MyObject 1657105963 U
db2 MyObject 1408005016 PWe'll incorporate this same code in a global procedure (sp__help) we'll place in the sybsystemprocs database :
use sybsystemprocs
go
create procedure sp__help
@objname varchar(255) ='sysobject'
as
select db_name() as 'database',name as 'object name',id,type
from sysobjects
where id = object_id(@objname)
goFor demo purposes we'll make our calls to sp__help from the master database :
use master
go
exec db1..sp__help 'MyObject'
exec db2..sp__help 'dbo.MyObject'
go
database object name id type
-------- ---------------- ---------- ----
db1 MyObject 1657105963 U
database object name id type
-------- ---------------- ---------- ----
db2 MyObject 1408005016 P Notice that we use the database name (db1, db2) to fully qualify the stored proc name (as opposed to fully qualifying the object name as in OP's sample query).
NOTES:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.