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

create constraint error

Hi.

I have a procedure with this in it (there are no other references to
asset_number_bak_tmp_pk in the procedure and it calls nothing else written by
me, just system calls or normal dml).

create table #asset_bak(
asset_number varchar(60) not null,
asset_desc varchar(100) null,
location varchar(40) null,
constraint asset_number_bak_tmp_pk primary key clustered (asset_number))

When I run the procedure, I get this message:

(1 row(s) affected)
Msg 2714, Level 16, State 4, Procedure updatenavharrierdb, Line 19
There is already an object named 'asset_number_bak_tmp_pk' in the database.
Msg 1750, Level 16, State 0, Procedure updatenavharrierdb, Line 19
Could not create constraint. See previous errors.

How can I find where else the system thinks this constraint exists?
I tried this but it only finds it in one place (one row in the result set),
i.e. my procedure:

select sysobjects.name, syscomments.text
from sysobjects, syscomments
where sysobjects.id = syscomments.id and
((lower(sysobjects.name) like '%asset_number_bak_tmp_pk%') or
(lower(syscomments.text) like '%asset_number_bak_tmp_pk%'))

Is this somehow a case where I need to do something dynamically, or purge some
information? I thought temp tables and their crony constraints disappeared
after the procedure exited.

thanks
Jeff Kish
May 16 '07 #1
2 8090
On Wed, 16 May 2007 08:41:50 -0400, Jeff Kish <je*******@mro.comwrote:
>Hi.

I have a procedure with this in it (there are no other references to
asset_number_bak_tmp_pk in the procedure and it calls nothing else written by
me, just system calls or normal dml).

create table #asset_bak(
asset_number varchar(60) not null,
asset_desc varchar(100) null,
location varchar(40) null,
constraint asset_number_bak_tmp_pk primary key clustered (asset_number))

When I run the procedure, I get this message:

(1 row(s) affected)
Msg 2714, Level 16, State 4, Procedure updatenavharrierdb, Line 19
There is already an object named 'asset_number_bak_tmp_pk' in the database.
Msg 1750, Level 16, State 0, Procedure updatenavharrierdb, Line 19
Could not create constraint. See previous errors.

How can I find where else the system thinks this constraint exists?
I tried this but it only finds it in one place (one row in the result set),
i.e. my procedure:

select sysobjects.name, syscomments.text
from sysobjects, syscomments
where sysobjects.id = syscomments.id and
((lower(sysobjects.name) like '%asset_number_bak_tmp_pk%') or
(lower(syscomments.text) like '%asset_number_bak_tmp_pk%'))

Is this somehow a case where I need to do something dynamically, or purge some
information? I thought temp tables and their crony constraints disappeared
after the procedure exited.

thanks
Jeff Kish
I got around the problem by removing the 'constraint name' clause.
I guess it is optional, but I still wonder is it 'wrong' to have a named
constraint on a temporary table, and shouldn't it of gone away with the table
at the end of procedure execution?

thanks for the illumination, shots, etc.
Jeff Kish
May 16 '07 #2
Jeff Kish (je*******@mro.com) writes:
I got around the problem by removing the 'constraint name' clause. I
guess it is optional, but I still wonder is it 'wrong' to have a named
constraint on a temporary table, and shouldn't it of gone away with the
table at the end of procedure execution?
Correct. For regular tables it is good practice to explicitly name your
constraints. But for temp tables you should never do it. The point with
temp tables is that two different sessions can create the same table without
conflict, because the real name behind the scenes is padded with some stuff
to make it unique. But if you name the constraints you lose this.

Keep in mind that all temp tables end up in sys.objects, and this table
(well view) also includes names of constraints.
--
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
May 16 '07 #3

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

Similar topics

1
by: js | last post by:
I am trying to create a primary key constraint on a view in the following statement. However, I got an error ORA-00907: missing right parenthesis. If the CONSTRAINT clause is removed, then the...
12
by: Tuhin Kumar | last post by:
Hi, Oracle give the error ORA-01418 when I try to do the following; Create unique index t1_pk on TABLE1(EntryId DESC) ; If the I try to add primary key Contraint using the above index t1_pk...
9
by: expect | last post by:
Hello, Trying to get this MySql create table command to work, no luck. create sequence serial; CREATE TABLE outbound ( source char(100) default '', destination char(100) default '', sport...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
0
by: BRINER Cedric | last post by:
Synopsis CREATE { TEMPORARY | TEMP } ] TABLE /table_name/ ( { /column_name/ /data_type/ ] | /table_constraint/ } ) ) ] ... ...
1
by: ibiza | last post by:
Hi all, I am using ASP.NET 2.0 Membership system, which is driving me nuts. I have my users, which I create correctly. Then I have a table "Models" which contains models, created by different...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
11
by: raylopez99 | last post by:
Keep in mind this is my first compiled SQL program Stored Procedure (SP), copied from a book by Frasier Visual C++.NET in Visual Studio 2005 (Chap12). So far, so theory, except for one bug...
2
by: jarea | last post by:
I have read quite a bit about this error but I have yet to find the solution to my problem. I am trying to execute the following mysql statement: alter table line_items add...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.