|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
inserting into table with foreign keys
I've posted this in the general database forum as well but think it is more sql server specific. I have three tables as below. My problem is that when I insert anything into has_quote, cat_ref and cust_id are both null. Any ideas on how to get round this? Thanks
![]() Code:
CREATE TABLE Item (
cat_ref INT IDENTITY(1,1) PRIMARY KEY,
descrip VARCHAR(50),
date_added SMALLDATETIME,
cat_type VARCHAR(20),
contract VARCHAR(10),
cost_price SMALLMONEY,
supplier_name VARCHAR(20),
supplier_phone VARCHAR(20))
CREATE TABLE has_quote (
quote_id INT IDENTITY (1,1) PRIMARY KEY,
installation_charge SMALLMONEY,
date_of_quote SMALLDATETIME,
commercial_markup SMALLMONEY,
service_desk_contact VARCHAR(20),
category INTEGER,
date_last_pricecheck SMALLDATETIME,
cat_ref INT FOREIGN KEY
REFERENCES Item(cat_ref),
cust_id INT FOREIGN KEY
REFERENCES Customer(cust_id))
CREATE TABLE Customer (
first_name VARCHAR(10),
surname VARCHAR(10),
customer_phone VARCHAR(20),
contract VARCHAR(10),
location VARCHAR(20),
email VARCHAR(50),
cust_id INT IDENTITY (1,1) PRIMARY KEY)
|
|
#2
|
||||
|
||||
|
foreign keys do not populate themselves automatically
you have to do it when you do the INSERT into has_quote, you have to provide the values of the foreign keys |
|
#3
|
|||
|
|||
|
Specifying the value in an insert doesnt work for identity columns though? Will it work for non identity columns?
Thanks ![]() |
|
#4
|
||||
|
||||
|
yes, if you specify a value for a non-identity column, that will work
![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > foreign keys IDENTITY |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|