•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,561 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 2710 | Replies: 3
•
•
Join Date: Aug 2007
Posts: 98
Reputation:
Rep Power: 2
Solved Threads: 0
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?
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?
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Loading All Database Name (ASP.NET)
- Need help displaying single database values (ASP.NET)
- database connection (ASP.NET)
- How to access and modify values of a OLE object(Excel Worksheet) (Visual Basic 4 / 5 / 6)
- need your help with database access (Visual Basic 4 / 5 / 6)
- Inserting a new Access Database Record (VB.NET)
- how to open a jpg from mysql database (PHP)
- Unable to insert form data into a database (ASP)
- accessing private data members (C++)
Other Threads in the MS SQL Forum
- Previous Thread: Problem
- Next Thread: Odd issue with LIKE operator



Threaded Mode