'There is already an object named 'ProductID' in the database.'

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

'There is already an object named 'ProductID' in the database.'

 
0
  #1
Oct 30th, 2007
Hey guys!

I seem to be posting here a lot the past few days but as I am new to SQL Server I am finding to quite a pain to get used to!

I am having a problem referencing foreign keys. I did post another thread about this but this is a slightly different problem.

everytime I try to reference a foreign key SQL Server says -
'There is already an object named 'ProductID' in the database.'

yes there is another Product ID in the Product table, why won't SQL Server recognise that it is a foreign key and needs to be in this table too? This is happening quite a lot when I am creating the tables and trying to reference the foreign key (not just ProductID). Here is the code for two of my tables:-

CREATE TABLE HireLine (
HireID INT IDENTITY NOT NULL ,
ProductID INT NOT NULL,
Quantity INT NULL,
PRIMARY KEY (HireID),
CONSTRAINT ProductID FOREIGN KEY (ProductID)
REFERENCES Product (ProductID)
ON DELETE CASCADE ON UPDATE CASCADE,
);


CREATE TABLE CorderLine (
CorderID INT,
ProductID INT,
Quantity INT NOT NULL,
PRIMARY KEY (CorderID, ProductID),
CONSTRAINT CorderID FOREIGN KEY (CorderID)
REFERENCES Corder (CorderID)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT ProductID FOREIGN KEY (ProductID)
REFERENCES Product (ProductID)
ON DELETE CASCADE ON UPDATE CASCADE,
);


has anyone any ideas of where I am going wrong?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,122
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 129
debasisdas's Avatar
debasisdas debasisdas is online now Online
Postaholic

Re: 'There is already an object named 'ProductID' in the database.'

 
0
  #2
Nov 1st, 2007
This problem is because you are trying to create two objects by same name. You are creating a column and a constraint by the same name with in a table . this why u are getting this error . Try to use different name for the coumn and the constraint.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: 'There is already an object named 'ProductID' in the database.'

 
0
  #3
Nov 1st, 2007
Originally Posted by debasisdas View Post
This problem is because you are trying to create two objects by same name. You are creating a column and a constraint by the same name with in a table . this why u are getting this error . Try to use different name for the coumn and the constraint.
Thanks for your reply!

I am trying to make the ProductID column the foreign key. I thought that using a constraint like this was how to make it a foreign key. How would i code this? would I say:-

CREATE TABLE HireLine (
HireID INT IDENTITY NOT NULL ,
ProductID INT NOT NULL,
Quantity INT NULL,
PRIMARY KEY (HireID),
CONSTRAINT FK_ProductID FOREIGN KEY (ProductID)
REFERENCES Product (ProductID)
ON DELETE CASCADE ON UPDATE CASCADE,
);


Thanks
GLT
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: 'There is already an object named 'ProductID' in the database.'

 
0
  #4
Nov 1st, 2007
Yep, that's it
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC