MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 2nd, 2004, 07:57 AM
sql asp sql asp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: UK
Posts: 259 sql asp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 51 sec
Reputation Power: 5
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)

Reply With Quote
  #2  
Old August 2nd, 2004, 02:22 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 42 m 2 sec
Reputation Power: 981
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
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old August 3rd, 2004, 03:08 AM
sql asp sql asp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: UK
Posts: 259 sql asp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 51 sec
Reputation Power: 5
Specifying the value in an insert doesnt work for identity columns though? Will it work for non identity columns?

Thanks

Reply With Quote
  #4  
Old August 3rd, 2004, 05:15 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 42 m 2 sec
Reputation Power: 981
yes, if you specify a value for a non-identity column, that will work


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > foreign keys IDENTITY


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway