473,666 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

alter table query not working after working at least once. MS SQL2000

drop table [dbo].[begin_call_temp]
CREATE TABLE [dbo].[begin_call_temp] (
[Event_Datetime] [datetime] NULL ,
[Machine_ID] [varchar](16) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS
NULL ,
[Line] [smallint] NULL ,
[Outbound_Line] [smallint] NULL ,
[Call_Number] [varchar](16) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS
NULL ,
[Outbound_Call_N umber] [varchar](16) COLLATE
SQL_Latin1_Gene ral_CP1_CI_AS NULL ,
[dc_dialstr] [varchar](75) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS
NULL ,
[ANI] [varchar](75) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL ,
[DNIS] [varchar](75) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL ,
[ANI_Name] [varchar](75) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL ,
[Call_Begin_Date time] [datetime] NULL ,
[identity] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]

ALTER TABLE [dbo].[begin_call_temp] WITH NOCHECK ADD
CONSTRAINT [PK_begin_call_t emp] PRIMARY KEY CLUSTERED
([identity]) ON [PRIMARY]

Table already exists.
[Microsoft][ODBC SQL Server Driver][SQL Server]There is already an
object named 'PK_begin_call_ temp' in the database.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.

This works the first time then after some period of time gets into a
state where this error is all I get...makes no sense to me. The
server is MS SQL 2000.

Thanks
David
Jun 27 '08 #1
7 2791
(qu*******@yaho o.com) writes:
Table already exists.
[Microsoft][ODBC SQL Server Driver][SQL Server]There is already an
object named 'PK_begin_call_ temp' in the database.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.

This works the first time then after some period of time gets into a
state where this error is all I get...makes no sense to me. The
server is MS SQL 2000.
I was not able to reproduce the problem. But as it complains on the
primary key only, and not the table, I would guess that the problem
is that you have another table with the same name for the PK.

Run

SELECT object_name(par ent_obj) FROM sysobjects
WHERE name = 'PK_begin_call_ temp'

to find out.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #2
On Jun 23, 4:47*pm, Erland Sommarskog <esq...@sommars kog.sewrote:
*(quincy...@yah oo.com) writes:
Table already exists.
[Microsoft][ODBC SQL Server Driver][SQL Server]There is already an
object named 'PK_begin_call_ temp' in the database.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
This works the first time then after some period of time gets into a
state where this error is all I get...makes no sense to me. *The
server is MS SQL 2000.

I was not able to reproduce the problem. But as it complains on the
primary key only, and not the table, I would guess that the problem
is that you have another table with the same name for the PK.

Run

* *SELECT object_name(par ent_obj) FROM sysobjects
* *WHERE name = 'PK_begin_call_ temp'

to find out.
Ok I think we are on to something here...not sure what...I get back
one cell with begin_call in it for this query.
The application when it works does the following:
We have a table begin_call we want to modify it in some arbitrary
way. So we do this.
We create begin_call_temp with the structure we want.
Then we transfer existing data from begin_call to begin_call_temp
using inerrt into.
Then we drop begin_call. .
Then we do a sp_rename begin_call_temp begin_call.

This entire sequence has worked at least once. Then we manually
remove the added fields to begin_call with server management studio
and try again, and it fails. Most likely something left over from my
choice of how to do the rename. But not sure what exactly.

Please enlgihten me...if this helps your understanding of what might
be happening.
Thanks,
David

>
--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se

Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx
Jun 27 '08 #3
On Jun 23, 11:00*pm, quincy...@yahoo .com wrote:
On Jun 23, 4:47*pm, Erland Sommarskog <esq...@sommars kog.sewrote:
*(quincy...@yah oo.com) writes:
Table already exists.
[Microsoft][ODBC SQL Server Driver][SQL Server]There is already an
object named 'PK_begin_call_ temp' in the database.
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not create
constraint. See previous errors.
This works the first time then after some period of time gets into a
state where this error is all I get...makes no sense to me. *The
server is MS SQL 2000.
I was not able to reproduce the problem. But as it complains on the
primary key only, and not the table, I would guess that the problem
is that you have another table with the same name for the PK.
Run
* *SELECT object_name(par ent_obj) FROM sysobjects
* *WHERE name = 'PK_begin_call_ temp'
to find out.

Ok I think we are on to something here...not sure what...I get back
one cell with begin_call in it for this query.
The application when it works does the following:
We have a table begin_call we want to modify it in some arbitrary
way. *So we do this.
We create begin_call_temp with the structure we want.
Then we transfer existing data from begin_call to begin_call_temp
using inerrt into.
Then we drop begin_call. .
Then we do a sp_rename begin_call_temp begin_call.

This entire sequence has worked at least once. *Then we manually
remove the added fields to begin_call with server management studio
and try again, and it fails. *Most likely something left over from my
choice of how to do the rename. *But not sure what exactly.

Please enlgihten me...if this helps your understanding of what might
be happening.
Thanks,
David


--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se
Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
sure enough I manually delete begin_call and begin_call_temp and it
works again the first time. How do I avoid the conflict the second
time?

Thanks
David
Jun 27 '08 #4
quincy451@ wrote:
drop table [dbo].[begin_call_temp]
CREATE TABLE [dbo].[begin_call_temp] (
>
Table already exists.
[Microsoft][ODBC SQL Server Driver][SQL Server]There is already an
object named 'PK_begin_call_ temp' in the database.
As far as I've found, the "drop table" doesn't happen until it encounters a
"go" statement. I could of course be completely wrong and there could be
some "drop table NOW" command.

Andrew
Jun 27 '08 #5
On Mon, 23 Jun 2008 21:00:57 -0700 (PDT), qu*******@yahoo .com wrote:

(snip)
>Please enlgihten me...if this helps your understanding of what might
be happening.
Hi David,

This is likely a result of how SQL Server checks correctness of names
when parsing your batches. For table and column names, there are
basically two possibilities:

1. The table exists at the time of parsing. In that case, SQL Server
will go on to check if all referenced columns exist. If they don't, you
get an error message.

2. The table does not exist at the time of parsing. In that case, SQL
Server assumes that it will somehow be created before the parsed command
will actually be executed, so no further checking takes place. This is
called deferred name resolution, as you defer the resolution of column
names from parse time to run time.

The first time you executed the batch, the table didn't exist yet so
deferred name resolution was used. By the time the "prblem" query was
executed, the table had been created and then altered to add the extra
column.

The second execution, the table did exist, so SQL Server wanted to check
the column names - and now you get an error because at parse time, the
ALTER TABLE has not yet been executed so the column is missing.

The best way to solve this is to cut up your SQL script in several
batches by interspersing it with batch seperators (GO) at well-chosen
locations. Parsing is done per batch, so if you make sure that the
"problem" query is in a batch that will be submitted after the batch
containing the ALTER TABLE, you'll have no problems - this batch will
now be parsed after adding the column to the table so you won't get any
errors.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Jun 27 '08 #6
(qu*******@yaho o.com) writes:
Ok I think we are on to something here...not sure what...I get back
one cell with begin_call in it for this query.
The application when it works does the following:
We have a table begin_call we want to modify it in some arbitrary
way. So we do this.
We create begin_call_temp with the structure we want.
Then we transfer existing data from begin_call to begin_call_temp
using inerrt into.
Then we drop begin_call. .
Then we do a sp_rename begin_call_temp begin_call.

This entire sequence has worked at least once.
Yes, it works the first time. It does not work the second time, because
apparently you forgot to rename the primary key when you renamed the
table.


--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #7
On Jun 24, 3:55*pm, Erland Sommarskog <esq...@sommars kog.sewrote:
*(quincy...@yah oo.com) writes:
Ok I think we are on to something here...not sure what...I get back
one cell with begin_call in it for this query.
The application when it works does the following:
We have a table begin_call we want to modify it in some arbitrary
way. *So we do this.
We create begin_call_temp with the structure we want.
Then we transfer existing data from begin_call to begin_call_temp
using inerrt into.
Then we drop begin_call. .
Then we do a sp_rename begin_call_temp begin_call.
This entire sequence has worked at least once. *

Yes, it works the first time. It does not work the second time, because
apparently you forgot to rename the primary key when you renamed the
table.
Yes I added
EXEC sp_rename 'begin_call_tem p.PK_begin_call _temp',
'PK_begin_call' ,'index';
Before
EXEC sp_rename 'begin_call_tem p','begin_call' ;

And it all seems to work.
Thank you,
David
>
--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se

Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx
Jun 27 '08 #8

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

Similar topics

2
44281
by: Heist | last post by:
Hi, I just want to know to turn this: CREATE TABLE . ( NOT NULL , (50) COLLATE French_CI_AS NULL , NOT NULL , (50) COLLATE French_CI_AS NOT NULL , NULL , NULL ) ON into this:
1
21732
by: Stephen Miller | last post by:
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( NOT NULL , NOT NULL ) ALTER TABLE @Test DROP COLUMN Col2
7
5395
by: Jon Combe | last post by:
I have created the following test SQL code to illustrate a real problem I have with some SQL code. CREATE TABLE JCTable ( CustomerName varchar(50) ) ALTER TABLE JCTable ADD CustomerNo int INSERT INTO JCTable ( CustomerName , CustomerNo ) VALUES ( 'Jon Combe' , 1 ) INSERT INTO JCTable ( CustomerName , CustomerNo ) VALUES ( 'Bill Gates' , 1 ) UPDATE JCTable SET CustomerNo = 2 WHERE CustomerName = 'Jon Combe'
0
1496
by: anzenews | last post by:
Hello! I have a weird problem... The application I use issues this SQL from time to time: alter table t modify id int(6) unique not null auto_increment; The problem is that this SQL adds a key on id every time it is run! mysql> show keys;
4
5870
by: maricel | last post by:
Could someone confirm which tablespace is being used when running ALTER & CREATE INDEX. Is it the tempspace or the tablespace where the table resides? Many thanks, maricel
0
6233
by: Gianfranco | last post by:
Hi, I'm not familiar at access and at VBA either, so I need some help or at least some hint please. I have table "availabledrivers", coming from a query to the table "drivers". Then I have a table "availablebus" coming from a query to "bus". Bus and Drivers have autonumber ID, so the tables I get have the IDs screwed up..I mean..there are "holes" in them..it's like 1,2,5,7,11,20 etc Now..I need to link the 2 resulting table...and I have...
3
2610
by: Michael Charney | last post by:
I am trying to alter a table that I imported data to. I can import the data just fine but when I run the following command: ALTER TABLE tblimport ADD COLUMN admit_date SmallDateTime It gives me the following error: Incorrect syntax near the keyword 'COLUMN'. I have tried several different versions of this but it always fails at this
1
3494
by: vasilip | last post by:
I'm testing out db2 for a project I'm starting that requires proper xml support and I can't seem to get both xml and spatial data to work well in the same table. Once having created a table containing both xml and spatial data fields I can't seem to find a way to alter the table I have created a table containing an id, xmldata field and a ST_Point If I try to drop the xml field with ALTER TABLE TEST DROP COLUMN
1
6856
by: Halfdood | last post by:
I am working on a data migration project using a pre-made SQL 2005 database. We need to migrate data to over 300 different talbes and the records number 20 million plus for some of the tables. We need to be able to insert values into multiple identity columns, so therefore SET IDENTITY_INSERT ON/OFF wont work. We can't simply use the interface either as it means that a miss click or a moment of absent mindedness can cause a world of...
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.