Solved

SQL SERVER MANAGEMENT STUDIO: Create Table in Stored Procedure and view in object brower

Posted on 2007-03-27
12
742 Views
Last Modified: 2008-06-28
Hello,

How do I create a table in a stored procedure and view it in management studio?

I've tried a create table command and a select into command. Both execute without errors. However the Object Explorer does not seem to register that a table exists in the selected database. What's the deal? When I create a table in a stored procedure where does it go? Is it a temporary table? How do I verify the table has been correctly populated?

Any help is appreciated,

Ryan

CREATE TABLE CEA.DBO.RYAN_TEMP
      (POLICY_ID INT)
      
      CREATE TABLE CEA.DBO.CEA_TRANS
      (POLICY_ID INT)
INSERT INTO RYAN_TEMP
                      (POLICY_ID)
VALUES     (96)
            SELECT policy_id
      INTO CEA.DBO.RYAN_TEMP
      FROM POLICY
      WHERE policy_id = 96
0
Comment
Question by:888_ryan_888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18801538
>>However the Object Explorer does not seem to register that a table exists in the selected database. What's the deal? <<
Have you tried refreshing?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18801554


CREATE TABLE cea.DBO.RYAN_TEMP
      (POLICY_ID INT)
CREATE TABLE cea.DBO.CEA_TRANS
      (POLICY_ID INT)

-- try to use fully qualified names in the insert/select part too

INSERT INTO cea.DBO.RYAN_TEMP (POLICY_ID)
VALUES     (96)

SELECT * FROM cea.DBO.RYAN_TEMP
0
 

Author Comment

by:888_ryan_888
ID: 18801555
Yes, I've tried refreshing.

Can you view a table created through a stored procedure?

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:888_ryan_888
ID: 18801560
I should be able to view the table regardless of values that are present in the table.

Can you view a table created in a stored procedure?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18801576
you can check something like this immediately after createing

create table test( i int)
If OBJECT_ID('test') IS NOT NULL
  Print  'table created'
Else
  Print 'No table available'
0
 

Author Comment

by:888_ryan_888
ID: 18801667
hmmm i can't get the object_id code to work, also  I've searched the drives for anything named ryan_temp and nothing comes up.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18801742
try this

SELECT OBJECT_ID('cea.DBO.RYAN_TEMP')
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18801756
>>I've searched the drives for anything named ryan_temp and nothing comes up. <<
That could be viewed by some as a wild goose chase.
0
 

Author Comment

by:888_ryan_888
ID: 18801804
yeah, the select doesn't fail, so it exists somewhere as something, but evidently not a table viewable in the object explorer. The idea here is to populate a table for export to text as a flat file. I'll need to view the table and may export it through ms access in which case the table will actually need to real in the same way that all of the other dbos in the database exist.

0
 

Author Comment

by:888_ryan_888
ID: 18801805
hahaha ... as could this, simply the only option available to me right now,
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21890440
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question