Solved

Create Table Problem

Posted on 1998-08-19
6
189 Views
Last Modified: 2010-03-19
Greetings,
I am trying to create a table using using a sp_ and the following code:

CREATE TABLE Summary_Tbl
(Criimi             varchar(6),
PropertyNBR             int,
Report_Period            datetime,
ChartofAccount_Code      varchar(5),
Revenue                  money,
Expenses            money,
Excluded            money)

The sp seems to work fine (i.e., no errors) but the table is never created. I get an Invalid Object Name error later when I try to merging a number of temp tables into Summary_Tbl.

What's up? Besides the sky....

Thanks,
Brad
0
Comment
Question by:bhummel
6 Comments
 
LVL 4

Expert Comment

by:vvk
ID: 1089631
Does your script working fine when you start it from isqlw window?
0
 
LVL 2

Accepted Solution

by:
mvz121697 earned 100 total points
ID: 1089632
You can only create temporary tables from within a stored proc.
They are created in database tempdb and are only there as long as your sp runs.
0
 

Author Comment

by:bhummel
ID: 1089633
I found that out last night. So, I created the table using enterprise manager. What I want to do is keep the same table but remove the records (I though "DROP TABLE" would do this) but now when I reference the table I get:
Invalid object name 'Statement_Summary_Tbl'
when I try to INSERT INTO 'Statement_Summary_Tbl'

Is there a better way to remove all the records each time the sp is executed?

FYI- vvk I am now doing all of this in Isql.

Thanks,
Brad
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 2

Expert Comment

by:mvz121697
ID: 1089634
With DROP TABLE you remove the whole table structure !
To remove only the records, just do:

DELETE FROM Table_Name


0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1089635
bhummel,

A correction to my first answer,
It _is_ possible to create a table from within a stored proc.
(At least with SQL-Server 6.5)

I think your DROP TABLE command was your problem in the first place.
This command does totally remove the table.

0
 
LVL 2

Expert Comment

by:formula
ID: 1089636
Within a stored procedure, I use TRUNCATE TABLE to keep the table structure and get rid of the records.  It's faster than
DELETE because it does not log individual row deletions.  If you
table doesn't contain rows you want to keep permanently, its the way to go.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

856 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