Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:43:00+00:00 2026-05-16T17:43:00+00:00

I have a stored procedure (see below) which inserts data into a physical table

  • 0

I have a stored procedure (see below) which inserts data into a physical table and then joins information with sys.databases. I was thinking that would it be better to not have a physical table for data insertion? Would it be better to fetch these results into a table variable within this procedure? If so, how to do that?

CREATE PROCEDURE dbo.PROC_getDbInfo
AS
    SET NOCOUNT ON
    GO
    TRUNCATE TABLE dbo.dbinfo
    GO
    EXECUTE sp_msforeachdb 'insert into dbo.dbinfo 
            select  ''?'' as name,
                    type_desc, 
                    physical_name, 
                    state_desc, 
                    size * 1.0/128 as size_in_mb, 
                    max_size, 
                    growth * 1.0/128 as growth_in_mb, 
                    is_percent_growth,
                    is_read_only    
    from [?].sys.database_files'

    GO

    SELECT  @@SERVERNAME as instance_name,
        f.name,
        d.create_date,
        d.compatibility_level,
        d.collation_name,
        d.user_access_desc,
        d.state_desc,
        d.recovery_model_desc,
        d.page_verify_option_desc,
        d.log_reuse_wait_desc,
        f.type_desc, 
        f.physical_name, 
        f.state_desc, 
        f.size_in_mb, 
        f.max_size, 
        f.growth_in_mb, 
        f.is_percent_growth,
        f.is_read_only  
    FROM dbo.dbinfo AS f INNER JOIN
            sys.databases AS d
                ON f.name = d.name
    ORDER BY f.name
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:43:01+00:00Added an answer on May 16, 2026 at 5:43 pm

    You’ll have to use a table. Either global temp (##) or a normal table.

    A table variable will not be in scope for the sp_msforeachdb call if declared for the stored proc, and not visible to the stored proc if declared in sp_msforeachdb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would someone please help me. I have a stored procedure (see below) for data
I have a stored procedure which update a table based on such calculation and
I have a stored procedure in oracle which is using cursor.Its fetching the data
I currently have the following code in a stored procedure (see below). In an
I currently have a stored procedure which returns data and displayed in my report
I have a stored procedure in which if I write the following query without
I have a stored procedure which returns sys_refcursor and I am trying to fetch
I have a stored procedure that returns data in the format of: Date |
Quite a simple question. In SQL 2008 if I have a stored procedure (see
I have written a simple stored procedure for updating a record which isn't working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.