|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
update table, foreign keys etc
I have two tables as below. I want to update a quote and change the item for which it is for. So I want to do an update statement to change the cat_ref that the quote is for. However, when I do this I get a foreign key conflict with cat_ref in the item table. How do I get around this? Thanks
![]() Code:
CREATE TABLE Item (
cat_ref VARCHAR(5)PRIMARY KEY,
descrip VARCHAR(50),
date_added SMALLDATETIME,
cat_type VARCHAR(20))
CREATE TABLE has_quote (
quote_id INT IDENTITY (1,1) PRIMARY KEY,
date_last_pricecheck SMALLDATETIME,
cat_ref VARCHAR(5)FOREIGN KEY
REFERENCES Item(cat_ref)
ON DELETE CASCADE,
first_name VARCHAR(10),
surname VARCHAR(10),
FOREIGN KEY (first_name, surname)
REFERENCES Customer(first_name, surname)
ON DELETE CASCADE
ON UPDATE CASCADE)
|
|
#2
|
|||
|
|||
|
Does the cat_ref exists in the item table?
__________________
El éxito consiste en una serie de pequeñas victorias día a día MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html |
|
#3
|
|||
|
|||
|
Hi, yes it does.... I've changed my tables slightly and am still getting foreign key conflict errors with cat_ref when inserting into and updating has_quote.
Code:
CREATE TABLE Item ( cat_ref VARCHAR(5)PRIMARY KEY, descrip VARCHAR(50), date_added SMALLDATETIME, cat_type VARCHAR(20), CREATE TABLE has_quote ( quote_id INT IDENTITY (1,1) PRIMARY KEY, date_of_quote SMALLDATETIME, cat_ref VARCHAR(5)FOREIGN KEY REFERENCES Item(cat_ref), first_name VARCHAR(10), surname VARCHAR(10), customer_phone VARCHAR(20), FOREIGN KEY (first_name, surname, customer_phone) REFERENCES Customer(first_name, surname, customer_phone) ON DELETE CASCADE ON UPDATE CASCADE) |
|
#4
|
|||
|
|||
|
Quote:
Google Brought me to this thread. I'm having the same problem. I'm trying to alter an existing table to add foreign keys. When I try to do the following: ALTER TABLE Cancer_Normalized_Table ADD CONSTRAINT valid_MSA FOREIGN KEY(MSAKey) REFERENCES MSA_KEYS(FK) I'm getting the error: ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'valid_MSA'. The conflict occurred in database 'Cancer', table 'MSA_KEYS', column 'FK'. |
|
#5
|
|||
|
|||
|
sql_asp can you post the insert/update syntax you are using?
|
|
#6
|
|||
|
|||
|
Sure...
![]() Code:
SQLStmt = "INSERT into has_quote (date_of_quote,cat_ref, first_name,surname,customer_phone) "
SQLStmt = SQLStmt & "VALUES ('" & date_of_quote & "', '" & cat_ref & "', '" & first_name & "', '" & surname & "', '" & customer_phone & "')"
SQLStmt = "UPDATE has_quote SET " &_
"date_of_quote='" & date_of_quote & "', " &_
"cat_ref='" & cat_ref & "' " &_
"WHERE quote_id='" & quote_id & "' "
|
| Viewing: Dev Shed Forums > Databases > MS SQL Development > update table, foreign keys etc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|