在临时 table 上使用 sp_spaceused

Using sp_spaceused on a temporary table

我想做的就是搜索订阅者数据(我想检查更多临时 tables 的数据),然后直接将 sp_spaceused 的结果插入到临时 table 到另一个临时 table。 然后在计算完所有数据space和来自大约100个不同温度tables的行之后,然后输出或计算结果

SELECT DISTINCT
    t1.SubscriberGUID,
    t1.ItemGUID_Entity,
    t1.SubscriberID,
    t1.SubscriberRegionID,
    t1.SubscriberTypeID,
    t1.ID,
    t1.SubscriberNameFull,
    t1.SubscriberEmail,
    t1.SubscriberLogin,
    t1.SubscriberPassword,
    t1.Active,
    t1.DateCreated,
    t1.DateDeleted
INTO #Found_Subscriber
FROM (
        SELECT t100.*, ROW_NUMBER() OVER(Order BY (SELECT 1)) AS 'RowNumber'
        FROM
            #AllSubscribers t100
    ) AS t1
WHERE t1.RowNumber = @I

CREATE TABLE #FileSize
    (
        [name] NVARCHAR(128),
        [rows] INT,
        [reserved] VARCHAR(18),
        [data] VARCHAR(18),
        [index_size] VARCHAR(18),
        [unused] VARCHAR(18)
    )
    

INSERT INTO #FileSize exec sp_spaceused #Found_Subscriber
INSERT INTO #FileSize exec sp_spaceused #Found_SubscriberInfo
...

但这不起作用。它抛出一个错误说:

Msg 15009, Level 16, State 1, Procedure sp_spaceused, Line 120 [Batch Start Line 0] The object '#Found_Subscriber' does not exist in database 'd1' is invalid for this operation.

错误消息告诉您您在错误的数据库中调用 sp_spaceused。尝试:

EXEC tempdb.sys.sp_spaceused N'#Found_Subscriber';