473,397 Members | 1,960 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,397 software developers and data experts.

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_General_CP1_CI_AS
NULL ,
[Line] [smallint] NULL ,
[Outbound_Line] [smallint] NULL ,
[Call_Number] [varchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Outbound_Call_Number] [varchar](16) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[dc_dialstr] [varchar](75) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[ANI] [varchar](75) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DNIS] [varchar](75) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ANI_Name] [varchar](75) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Call_Begin_Datetime] [datetime] NULL ,
[identity] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]

ALTER TABLE [dbo].[begin_call_temp] WITH NOCHECK ADD
CONSTRAINT [PK_begin_call_temp] 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 2778
(qu*******@yahoo.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(parent_obj) FROM sysobjects
WHERE name = 'PK_begin_call_temp'

to find out.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.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...@sommarskog.sewrote:
*(quincy...@yahoo.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(parent_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...@sommarskog.se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/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...@sommarskog.sewrote:
*(quincy...@yahoo.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(parent_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...@sommarskog.se
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/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*******@yahoo.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****@sommarskog.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...@sommarskog.sewrote:
*(quincy...@yahoo.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_temp.PK_begin_call_temp',
'PK_begin_call','index';
Before
EXEC sp_rename 'begin_call_temp','begin_call';

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

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

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

Similar topics

2
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
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...
7
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...
0
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...
4
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
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...
3
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...
1
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.