473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unable to ALTER a temporary table in TSQL

Is it possible to ALTER a temporary table in TSQL (SQL2000)?

The following TSQL reports a syntax error at the ALTER TABLE line:

DECLARE @Test TABLE(
[Col1] [int] NOT NULL ,
[Col2] [int] NOT NULL
)
ALTER TABLE @Test
DROP COLUMN Col2

I was hoping this would work the same way as a normal table. For example:

CREATE TABLE [dbo].[Test] (
[Col1] [int] NOT NULL ,
[Col2] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE Test
DROP COLUMN Col2

EXEC sp_help Test

DROP TABLE Test
Jul 20 '05 #1
1 21682
You can alter a temporary table (# or ## prefix) but not a table
variable. One of the performance benefits of table variables is reduced
recompilations and permitting DDL against a table variable would force a
recompile.

If you must execute DDL here, consider a regular temp table. However, a
better solution would be to avoid DDL against a temporary object
entirely.

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Stephen Miller" <js******@hotmail.com> wrote in message
news:cd**************************@posting.google.c om...
Is it possible to ALTER a temporary table in TSQL (SQL2000)?

The following TSQL reports a syntax error at the ALTER TABLE line:

DECLARE @Test TABLE(
[Col1] [int] NOT NULL ,
[Col2] [int] NOT NULL
)
ALTER TABLE @Test
DROP COLUMN Col2

I was hoping this would work the same way as a normal table. For example:
CREATE TABLE [dbo].[Test] (
[Col1] [int] NOT NULL ,
[Col2] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE Test
DROP COLUMN Col2

EXEC sp_help Test

DROP TABLE Test

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Corrine | last post by:
Hi, I am creating a global temporary table that is session-specific. I insert a BLOB into this table, and then select the BLOB from this table into a ResultSet. The ResultSet sees this BLOB...
5
by: Jim Garrison | last post by:
Scenario: 1) Create a GLOBAL TEMPORARY table and populate it with one (1) row. 2) Join that table to another with about 1 million rows. The join condition selects a few hundred rows. ...
4
by: gonzal | last post by:
Hi Dose any body know why a temporary table gets deleted after querying it the first time (using SELECT INTO)? When I run the code bellow I'm getting an error message when open the temp table...
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
4
by: zbychu | last post by:
Hi Db2UDB version 8.2 Is possible difrent way than this DECLARE TT as select * from session.TT definition only;
3
by: vsaraog | last post by:
Hi everybody, I asked the following question but didn't get any reply. If anyone knows something about the problem, then please reply since I am really in a bind. Here is the question... I...
7
by: Larry | last post by:
Hi, I have unbelievable problems just to save a record! I make an input to a record in a subform, which has a temporary table as its recordsource. When I am done, and want to save the...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
0
by: bbaamm | last post by:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) If FileUpload1.HasFile Then Try ' alter path for your project ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.